RE: data attributes override method attributes?

2012-09-28 Thread Prasad, Ramit
Terry Reedy wrote: On 9/25/2012 4:07 PM, Ian Kelly wrote: On Tue, Sep 25, 2012 at 1:58 PM, Terry Reedy tjre...@udel.edu wrote: On 9/25/2012 11:03 AM, Chris Angelico wrote: Instance attributes override (shadow) class attributes. except for (some? all?) special methods Those names

Re: data attributes override method attributes?

2012-09-28 Thread Ian Kelly
On Fri, Sep 28, 2012 at 12:02 PM, Prasad, Ramit ramit.pra...@jpmorgan.com wrote: Just to make sure I am following, if you call foo.__len__() it goes to the instance code while if you do len(foo) it will go to class.__len__()? Yes: class Foo(object): ... def __len__(self): ...

Re: data attributes override method attributes?

2012-09-28 Thread Terry Reedy
On 9/28/2012 2:02 PM, Prasad, Ramit wrote: Just to make sure I am following, if you call foo.__len__() it goes to the instance code while if you do len(foo) it will go to class.__len__()? len(foo) calls someclass.__len__(foo) where someclass is foo.__class__or some superclass. If so, why?

Re: data attributes override method attributes?

2012-09-28 Thread Steven D'Aprano
On Fri, 28 Sep 2012 18:02:04 +, Prasad, Ramit wrote: Just to make sure I am following, if you call foo.__len__() it goes to the instance code while if you do len(foo) it will go to class.__len__()? If you call foo.__len__, the attribute lookup of __len__ will use the exact same search

Re: data attributes override method attributes?

2012-09-25 Thread alex23
On Sep 25, 11:41 pm, Jayden jayden.s...@gmail.com wrote: Dear All, In the Python Tutorial, Section 9.4, it is said that Data attributes override method attributes with the same name. But in my testing as follows: #Begin class A:         i = 10         def i():                 print

Re: data attributes override method attributes?

2012-09-25 Thread Peter Otten
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

Re: data attributes override method attributes?

2012-09-25 Thread alex23
On Sep 26, 12:08 am, Peter Otten __pete...@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

Re: data attributes override method attributes?

2012-09-25 Thread Steven D'Aprano
On Tue, 25 Sep 2012 06:41:43 -0700, Jayden wrote: Dear All, In the Python Tutorial, Section 9.4, it is said that Data attributes override method attributes with the same name. But in my testing as follows: #Begin class A: i = 10 def i(): print 'i' A.i

Re: data attributes override method attributes?

2012-09-25 Thread Peter Otten
alex23 wrote: On Sep 26, 12:08 am, Peter Otten __pete...@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

Re: data attributes override method attributes?

2012-09-25 Thread Chris Angelico
On Wed, Sep 26, 2012 at 12:54 AM, Peter Otten __pete...@web.de wrote: To me Data attributes override method attributes with the same name implies that data attributes take precedence over method attributes, not that they replace them only when there is an assignment of data after the method

Re: data attributes override method attributes?

2012-09-25 Thread Ulrich Eckhardt
Am 25.09.2012 16:11, schrieb alex23: On Sep 26, 12:08 am, Peter Otten __pete...@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

Re: data attributes override method attributes?

2012-09-25 Thread Terry Reedy
On 9/25/2012 11:03 AM, Chris Angelico wrote: On Wed, Sep 26, 2012 at 12:54 AM, Peter Otten __pete...@web.de wrote: To me Data attributes override method attributes with the same name implies that data attributes take precedence over method attributes, not that they replace them only when

Re: data attributes override method attributes?

2012-09-25 Thread Thomas Rachel
Am 25.09.2012 16:08 schrieb Peter Otten: 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. I jump

Re: data attributes override method attributes?

2012-09-25 Thread Ian Kelly
On Tue, Sep 25, 2012 at 1:58 PM, Terry Reedy tjre...@udel.edu wrote: On 9/25/2012 11:03 AM, Chris Angelico wrote: Instance attributes override (shadow) class attributes. except for (some? all?) special methods Those names are shadowed too. If you call foo.__len__() and the name is bound on

Re: data attributes override method attributes?

2012-09-25 Thread Terry Reedy
On 9/25/2012 10:54 AM, Peter Otten wrote: alex23 wrote: On Sep 26, 12:08 am, Peter Otten __pete...@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

Re: data attributes override method attributes?

2012-09-25 Thread Terry Reedy
On 9/25/2012 4:07 PM, Ian Kelly wrote: On Tue, Sep 25, 2012 at 1:58 PM, Terry Reedy tjre...@udel.edu wrote: On 9/25/2012 11:03 AM, Chris Angelico wrote: Instance attributes override (shadow) class attributes. except for (some? all?) special methods Those names are shadowed too. If you