Python exceptions: is there a way to find the exceptionattributes?

Pierre Rouleau pieroul at attglobal.net
Sun Dec 1 15:43:40 EST 2002


> 
> It sounds to me like you're doing this the hard way -- if you want an 
> exception object, you should be able to simply construct it, e.g.:
> 
> dir(TypeError())

You are right! So simple!

 >>> dir(IOError())
['__doc__', '__getitem__', '__init__', '__module__', '__str__', 'args', 'errno', 'filename', 'strerror']


> 
> This will give me a dir on an *instance* of TypeError, as opposed to:
> 
> dir(TypeError)
> 
> which will just give me the class info.
> 
> Of course, I might want to read:
> 
> TypeError().__doc__
> 
> (which I find more useful than just knowing the attributes, which are pretty 
> much the same for all built-in exceptions).

It really does not tell you much if you want to know what attributes to use.

 >>> IOError().__doc__
'I/O operation failed.'


> 
> Hope this helps,

It did!  Thanks!

Pierre



-- 
         Pierre Rouleau, ing.





More information about the Python-list mailing list