data attributes override method attributes?

Ulrich Eckhardt ulrich.eckhardt at dominolaser.com
Tue Sep 25 10:54:37 EDT 2012


Am 25.09.2012 16:11, schrieb alex23:
> On Sep 26, 12:08 am, Peter Otten <__pete... at web.de> wrote:
>> Jayden wrote:
>>> In the Python Tutorial, Section 9.4, it is said that
>>
>>> "Data attributes override method attributes with the same name."
>>
>> The tutorial is wrong here. That should be
>>
>> "Instance attributes override class attributes with the same name."
>>
>> As methods are usually defined in the class and data attributes are usually
>> set in the instance it will look like data override method attributes.
>
> But you can assign attributes on the class, which has the same impact,
> so the tutorial is correct.

You can assign attributes of the class or the instance, and you can 
assign with functions or data (actually, both functions and data are 
objects, Python doesn't make a distinction there). The important thing 
is that lookup first looks in the instance (where data attributes are 
usually set) before looking in the class (where method attributes are 
usually set). Observing typical use and deriving a rule from this is 
misleading though.


>> No, you're right. Please file a bug report athttp://bugs.python.org
>
> Didn't you just demonstrate the behaviour you're now saying is a bug?

I think he meant a bug in the tutorial, not in the implementation of Python.


Uli




More information about the Python-list mailing list