Python exceptions: is there a way to find the exception attributes?

Erik Max Francis max at alcyone.com
Sat Nov 30 21:13:33 EST 2002


Pat Notz wrote:

> You can also cast the exception into a string which -- if the
> exception class is properly designed -- should give you useful
> information.  For example:
> 
> try:
>     open('/foo.bar')
> except Exception, e:
>     print 'Exception occurred: %s' % str(e)
> 
> That's not exactly what you were asking for but maybe it'll help.

Note that the conversion to string via str ("cast" is a word that might
get Python people up in arms) is implicit with the %s format specifier.

-- 
 Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/
 __ San Jose, CA, USA / 37 20 N 121 53 W / &tSftDotIotE
/  \ No one knows what he can do until he tries.
\__/ Publilius Syrus
    Bosskey.net: Counter-Strike / http://www.bosskey.net/cs/
 A personal guide to Counter-Strike.



More information about the Python-list mailing list