NoneType Error

Gabriel Genellina gagsl-py2 at yahoo.com.ar
Mon Jun 16 02:33:16 EDT 2008


En Sun, 15 Jun 2008 05:35:18 -0300, Maryam Saeedi <ma.saeedi at gmail.com> escribió:

> I am using a python program on a lot of different documents and for few of
> them I will get NoneType error. I just want to skip those files and continue
> for others, I do this without a problem for
> IndexError,TypeError,ValueError,NameError :
>
> try:
>  ....
> except (IndexError,TypeError,ValueError,NameError):
>  ....
>
> but when I add NoneType it gives the following error:
> except (NoneType,IndexError,TypeError,ValueError,NameError):
> NameError: name 'NoneType' is not defined
>
> and if I do not use the NoneType then it does not go through either and
> stops the program when I get to such a file. Is there another name that
> captures this error?

NoneType is not an exception, but the type of the None object. Perhaps you're not interpreting correctly some error messages:

>>> x=None
>>> x()
Traceback (most recent call last):
   File "<stdin>", line 1, in <module>
TypeError: 'NoneType' object is not callable

(the exception raised is a TypeError; NoneType is part of the message).

It appears that you want to catch all exceptions, just use Exception for that:
try:
   ...
except Exception:
   ...

-- 
Gabriel Genellina




More information about the Python-list mailing list