problem with change to exceptions

Gabriel Genellina gagsl-py2 at yahoo.com.ar
Sun Jul 29 16:57:11 CEST 2007


En Fri, 27 Jul 2007 19:49:17 -0300, Neal Becker <ndbecker2 at gmail.com>  
escribió:

> import exceptions
>
> class nothing (exceptions.Exception):
>     def __init__ (self, args=None):
>         self.args = args
>
> if __name__ == "__main__":
>     raise nothing
>
> Traceback (most recent call last):
>   File "<stdin>", line 1, in <module>
>   File "/usr/tmp/python-3143hDH", line 5, in __init__
>     self.args = args
> TypeError: 'NoneType' object is not iterable
>
> I'll have to say, I don't understand this error.

If this is all your code, try using just:

class nothing(Exception): pass

if __name__ == "__main__":
     raise nothing

Exceptions are built-in since aeons ago, so you don't have to import the  
exceptions module.
The standard Exception class has an "args" attribute, and it's expected to  
be a tuple (not None). See  
<http://docs.python.org/lib/module-exceptions.html>

-- 
Gabriel Genellina




More information about the Python-list mailing list