HOWTO · Python
Python typeerror: object of type 'nonetype' has no len()
이 기사에서는 typeerror: 객체 유형 'nonetype'에 Python에서 len() 오류가 없습니다.
이 페이지의 내용
이 컴팩트 가이드는 파이썬에서 typeerror: object of type 'nonetype' has no len() 오류를 해결하는 방법에 대해 설명합니다. 이에 대한 간단한 설명이 있으며 모든 것을 명확하게 이해하기 위해 Python의 NoneType에 대해 조금 알아보겠습니다.
Python typeerror: object of type 'nonetype' has no len()수정
Python에서 데이터 세트에 none 값을 할당하면 길이가 없으므로 len() 함수를 사용할 수 없습니다. 다음 코드를 예로 살펴보십시오.
# an object of None type
i = None
# calling function to check the len
len(i) # error
위의 코드에서 NoneType의 i 길이를 찾으면 이 오류가 발생합니다. 함수가 작동할지 여부에 익숙하지 않은 경우 항상 내장 메서드를 사용하여 해당 함수가 있는지 여부를 찾을 수 있습니다.
이 오류의 경우 다음 코드를 사용하여 none 객체의 매직 함수를 찾을 수 있습니다.
# an object of None type
i = None
# calling function to check the len
# len(i)
# error
# built-in / magic functions of None object
print(dir(i))
아래는 위 코드의 출력이며, 보시다시피 none 객체의 길이를 찾는 데 사용할 수 있는 length 함수가 없습니다.
[
"__class__",
"__delattr__",
"__doc__",
"__format__",
"__getattribute__",
"__hash__",
"__init__",
"__new__",
"__reduce__",
"__reduce_ex__",
"__repr__",
"__setattr__",
"__sizeof__",
"__str__",
"__subclasshook__",
]