[Python-Dev] Traceback object has no __class__?

Nick Coghlan ncoghlan at gmail.com
Mon Apr 12 08:56:18 CEST 2010


Greg Ewing wrote:
> I thought type-class unification was supposed to mean
> that all objects now have a __class__ attribute. But
> traceback objects don't seem to:
> 
> import sys
> 
> try:
>   raise ValueError
> except ValueError:
>   tb = sys.exc_info()[2]
>   print tb
>   print tb.__class__

I'm not sure what build you're getting that behaviour on, but my svn
build of 2.6 has a __class__ attribute for traceback objects, as does
the kubuntu 9.10 python 2.6.4 system install.

>>> try:
...   raise ValueError
... except:
...   import sys
...   tb = sys.exc_info()[2]
...   print type(tb)
...   print dir(tb)
...   print tb.__class__
...
<type 'traceback'>
['__class__', '__delattr__', '__doc__', '__format__',
'__getattribute__', '__hash__', '__init__', '__new__', '__reduce__',
'__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__',
'__subclasshook__', 'tb_frame', 'tb_lasti', 'tb_lineno', 'tb_next']
<type 'traceback'>

Cheers,
Nick.

-- 
Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia
---------------------------------------------------------------


More information about the Python-Dev mailing list