class object's attribute is also the instance's attribute?

Dave Angel d at davea.name
Thu Aug 30 10:30:35 EDT 2012


On 08/30/2012 10:11 AM, Marco Nawijn wrote:
> On Thursday, August 30, 2012 3:25:52 PM UTC+2, Hans Mulder wrote:
>> <snip>
>>
> Learned my lesson today. Don't assume you know something. Test it first ;). I have done quite some programming in Python, but did not know that class attributes are still local to the instances. 

They're not.  They're just visible to the instances, except where the
instance has an instance attribute of the same name.  Don't be confused
by dir(), which shows both instance and class attributes.

Please show me an example where you think you observe each instance
getting a copy of the class attribute.  There's probably some other
explanation.




-- 

DaveA




More information about the Python-list mailing list