글

라벨이 TypeError: 'NoneType' object is not subscriptable인 게시물 표시

TypeError: 'NoneType' object is not subscriptable - 10 Causes and Fixes

이미지
TypeError: 'NoneType' object is not subscriptable means you used [...] on a value that is None . Python raises this the moment you write x[0] , x["key"] , or x[1:3] and x happens to be None - the subscript operator simply does not exist on the NoneType type. The traceback tells you where the subscript happened, not where the None came from. That gap is the whole debugging problem: the real bug is usually several lines (or several functions) earlier, at the point something returned None and you assumed it returned a dict, a list, or a string. This page lists the concrete ways a None gets into a subscript - functions with a missing return , mutating methods like sort() and append() , regex search() misses, dict.get() on an absent key, JSON null , DB queries with no rows - each with a reproduction, the fix, and a way to verify. If your case does not match any of them, work the diagnostic checklist instead. Error TypeError: 'NoneType' object i...