Tuesday 15 February 2011

python - How to catch - 'NoneType' object has no attribute 'something' -


I know what the error is:

  AttributeError: 'NoneType' in the object The feature is not something 'something'  

means, but I do not know how it can hold. Actually I want to see if my object has been created or not.

I have to do something like this:

  try: test = self.myObject.values ​​() except: print "error occurred"  

But every time I do this:

  attribute error: 'any type' object has no attribute 'value'  
< P> How can someone catch me?

You can use the hectar (object, name) method that returns true or false if If you try to use the attribute that does not exist, you will always get an exception.

If you still want to catch exceptions, then just try an exception / catch with the exception type 'attribute error'


No comments:

Post a Comment