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

Jacob Griffin picture Jacob Griffin · Jan 21, 2012 · Viewed 978.9k times · Source

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?

Answer

g.d.d.c picture g.d.d.c · Jan 21, 2012

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.