Attribute reference design

chamalulu henrik at chamalulu.com
Tue Jul 1 19:31:32 EDT 2008


On Jul 2, 1:17 am, Gary Herron <gher... at islandtraining.com> wrote:
> No need.   Also, you can define a class attribute (C++ might call it a
> static attribute) and access it transparently through an instance.
>
> class C:
>   aClassAttribute = 123
>   def __init__(self, ...):
>     ...
>
> c = C()
> ... do something with c.aClassAttribute ...
>

Actually, this is why I started too look into the attribute reference
mechanics to begin with. Coming from mostly C# development I think
it's weird to be able to refer to class attributes (static members)
through a class instance (object). But I think I'm getting the
picture. Function objects lay flat in memory (some heap...). When
defined inside classes they are wrapped in method objects. When
refered through classes or class instances they are unbound method
objects or bound method objects respectively. Am I on the right track?
I still don't get why these methods show up when I dir() a class
instance.

/Henrik



More information about the Python-list mailing list