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

Terry Hancock hancock at anansispaceworks.com
Sun Dec 1 04:53:37 EST 2002


On Saturday 30 November 2002 06:47 pm, Pierre Rouleau wrote:
> >     Pierre> It would be nice to be able to do that from the
> >     Pierre> interpreter.  The only thing i have found using dir() is
> >     Pierre> shown below and it does not give me the attributes.
>> > This is not something I have ever needed to do, but I'm curious: What
> > is wrong/inferior/unsatisfying about the dir approach?
>> It's not that big an issue, but you have to have an instance of the 
> exception to be able to dir() its attributes.  Therefore you have to 
> know how to create the exception.  [...]

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())

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).

Hope this helps,
Terry

--
Terry Hancock ( hancock at anansispaceworks.com )
Anansi Spaceworks  http://www.anansispaceworks.com




More information about the Python-list mailing list