Python exceptions: is there a way to find the exception attributes?
Erik Max Francis
max at alcyone.com
Sat Nov 30 17:53:49 EST 2002
Pierre Rouleau wrote:
> Is there a way to find out about the existence of these attributes
> without having to read the documentation, using the dir() function or
> something else?
>
> It would be nice to be able to do that from the interpreter. The only
> thing i have found using dir() is shown below and it does not give me
> the attributes.
...
> Of course, I could force an exception and print it like:
...
> Is this the only way ?
Without inspecting the code, probably. The details about the exception
are instance attributes, not class attributes, so you won't find them by
simple inspection of the class type; you'd have to look at the actual
code of the exception's __init__ method.
Especially in the face of user-defined exceptions, the best way to
proceed is by inspecting the instance attributes of an actual exception
object after the fact.
--
Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/
__ San Jose, CA, USA / 37 20 N 121 53 W / &tSftDotIotE
/ \ You are the lovers rock / The rock that I cling to
\__/ Sade
Church / http://www.alcyone.com/pyos/church/
A lambda calculus explorer in Python.
More information about the Python-list
mailing list