Finding the name of a class
John Salerno
johnjsal at NOSPAMgmail.com
Tue Aug 1 12:18:48 EDT 2006
Shane Hathaway wrote:
> Don't forget to file a bug.
I'm reluctant to call it a bug just yet. Here's more stuff below.
There's obviously a difference between old- and new-style classes. It
seems that as far as new-style is concerned, __name__ is an attribute of
__class__ (along with a bunch of other stuff), but not of Foo itself.
>>> class Foo(object):
pass
>>> dir(Foo)
['__class__', '__delattr__', '__dict__', '__doc__', '__getattribute__',
'__hash__', '__init__', '__module__', '__new__', '__reduce__',
'__reduce_ex__', '__repr__', '__setattr__', '__str__', '__weakref__']
>>> dir(Foo.__class__)
['__base__', '__bases__', '__basicsize__', '__call__', '__class__',
'__cmp__', '__delattr__', '__dict__', '__dictoffset__', '__doc__',
'__flags__', '__getattribute__', '__hash__', '__init__', '__itemsize__',
'__module__', '__mro__', '__name__', '__new__', '__reduce__',
'__reduce_ex__', '__repr__', '__setattr__', '__str__', '__subclasses__',
'__weakrefoffset__', 'mro']
>>> class Foo:
pass
>>> dir(Foo)
['__doc__', '__module__']
>>> dir(Foo.__class__)
Traceback (most recent call last):
File "<pyshell#9>", line 1, in -toplevel-
dir(Foo.__class__)
AttributeError: class Foo has no attribute '__class__'
More information about the Python-list
mailing list