I keep getting an error that says
AttributeError: 'NoneType' object has no attribute 'something'
The code I have is too long to post here. What general scenarios would cause this AttributeError
, what is NoneType
supposed to mean and how can I narrow down what's going on?
You are getting AttributeError: 'NoneType' object has no attribute 'something' because NoneType means that instead of an instance of whatever Class or Object you think you're working with, you've actually got None. It means that an assignment or function call up above failed or returned an unexpected result.
If you are getting an object that has no attribute error then the reason behind it is because your indentation is goofed, and you've mixed tabs and spaces.
The error “TypeError: 'NoneType' object is not iterable” occurs when you try to iterate over a NoneType object. Objects like list, tuple, and string are iterables, but not None. To solve this error, ensure you assign any values you want to iterate over to an iterable object.
NoneType means that instead of an instance of whatever Class or Object you think you're working with, you've actually got None
. That usually means that an assignment or function call up above failed or returned an unexpected result.
You have a variable that is equal to None and you're attempting to access an attribute of it called 'something'.
foo = None foo.something = 1
or
foo = None print(foo.something)
Both will yield an AttributeError: 'NoneType'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With