Why do I get AttributeError: 'NoneType' object has no attribute 'something'?


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?

5/9/2019 8:21:46 PM

Accepted Answer

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.

1/20/2012 11:40:07 PM

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


foo = None
print foo.something

Both will yield an AttributeError: 'NoneType'

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow