ClassName.attribute vs self.__class__.attribute
Bruno Desthuilliers
bruno.42.desthuilliers at websiteburo.invalid
Thu Jun 12 05:17:49 EDT 2008
Mike Orr a écrit :
(snip)
> 'self' has a .__class__ attribute because it's an
> instance, but MyClass and Superclass do not because they're already
> classes.
Not true for new-style classes:
>>> class Toto(object): pass
...
>>> Toto.__class__
<type 'type'>
(snip)
> I sometimes wish classes
> had a .__class__ attribute that's the class itself,
newstyle classes do have a class attribute, that refers to the metaclass.
> but I can see how
> that would cause its own confusion (and recursion).
FWIW, metaclasses do have a class attribute that refers to itself !-)
More information about the Python-list
mailing list