Attribute reference design

Gary Herron gherron at
Wed Jul 2 01:47:53 CEST 2008

chamalulu wrote:
> On Jul 2, 1:17 am, Gary Herron <gher... at> 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...). 

Not quite.  Not *flat memory* or a heap.  Modules are first class 
objects, and functions (and classes and anything else) defined at the 
top level of the module are *attributes* of the module. 

Gary Herron

> 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