ClassName.attribute vs self.__class__.attribute

Casey McGinty casey.mcginty at
Fri Jun 6 22:43:15 CEST 2008

On Thu, Jun 5, 2008 at 11:39 AM, Terry Reedy <tjreedy at> wrote:

> If you want to access the attribute of a particular class, to read or
> write, use that class.
>   SomeClass.attr
> Note that no instance is required or relevant.
> If you want to read the attrubute of the class of an instance (or the first
> superclass with the attribute, whatever that class might be, use self.attr
> or self.__class__.attr.  (Use the latter if the instance has (or might
> have) an attribute of the same name).
> For setting an attribute, self.attr = x sets it on the instance while
> self.__class__.attr = x sets it on its class.
>  <>

So the key here is that obj.__class__.attr  will only access  the immediate
child class name space, but SuperClass.attr will guarantee your are access
the first super class namespace? If that is true, then the bug makes sense.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the Python-list mailing list