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

Pierre Rouleau pieroul at attglobal.net
Sat Nov 30 18:40:37 EST 2002


>     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?
> 
> Thanks,
> John Hunter 
> 
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.  You could raise it, but that won't 
tell you the arguments you could pass unless you read the source code. 
That is not a big deal either if the exception you are looking for is a 
class, just look at __init__.  But if it is a builtin exception, you 
have to find a way to raise the exception by some code (not simply by 
raise since you are looking for those arguments), catch the exception 
and run dir on the exception instance.

I was looking for a quick way to look at exception attributes from 
within my programming environment when i have to decide what exception i 
should catch or which one i should raise and then what information i 
should pass inside the exception object.


-- 
         Pierre Rouleau, ing.
         Hull, Québec





More information about the Python-list mailing list