Re: What a curious assignment.

2005-11-23 Thread Steven D'Aprano
On Wed, 23 Nov 2005 00:17:32 -0800, [EMAIL PROTECTED] wrote: > > Steven D'Aprano wrote: >> [EMAIL PROTECTED] wrote: >> >> > Is there somthing wrong >> >> Kids today, don't they learn about inheritence? :-) [snip] > I believe he knows about inheritance, Hence my smiley. > but not about th

Re: What a curious assignment.

2005-11-23 Thread Mike Meyer
"[EMAIL PROTECTED]" <[EMAIL PROTECTED]> writes: > I believe he knows about inheritance, but not about the behaviour of > the assignment. In many other OO languages, I believe you cannot have > the same name for both instance variable and class variable. javascript > has similar behaviour. I think

Re: What a curious assignment.

2005-11-23 Thread bruno at modulix
[EMAIL PROTECTED] wrote: > [test 1] > class A: > > ...i = 1 > ... > a = A() A.i > > 1 > a.i > > 1 > A.i = 2 A.i > > 2 > a.i > > 2 > > > [test2] > class A: > > ...i = 1 > ... > a = A() A.i > > 1 > a.i > > 1 > a.i = 2 A.i

Re: What a curious assignment.

2005-11-23 Thread [EMAIL PROTECTED]
Steven D'Aprano wrote: > [EMAIL PROTECTED] wrote: > > > Is there somthing wrong > > Kids today, don't they learn about inheritence? :-) > > Python's object model is that instances inherit both > methods and attributes from the class (and > superclasses). Methods are just a special case of > at

Re: What a curious assignment.

2005-11-23 Thread Steven D'Aprano
[EMAIL PROTECTED] wrote: > Is there somthing wrong Kids today, don't they learn about inheritence? :-) Python's object model is that instances inherit both methods and attributes from the class (and superclasses). Methods are just a special case of attributes: the method is a callable att

Re: What a curious assignment.

2005-11-22 Thread Naveed
"A.i" is a class attribute. "a.i" at first is the same as "A.i". Once you set a.i = 2, you are actually creating a new data attribute called i for the instance a. This happens on the fly. So then when you reference a.i, it uses the instance data attribute, instead of the class attribute. This

Re: What a curious assignment.

2005-11-22 Thread [EMAIL PROTECTED]
[EMAIL PROTECTED] wrote: > [test 1] > >>> class A: > ...i = 1 > ... > >>> a = A() > >>> A.i > 1 > >>> a.i > 1 > >>> A.i = 2 > >>> A.i > 2 > >>> a.i > 2 > >>> > > [test2] > >>> class A: > ...i = 1 > ... > >>> a = A() > >>> A.i > 1 > >>> a.i > 1 > >>> a.i = 2 > >>> A.i > 1 > >>> a.i > 2 > >>

Re: What a curious assignment.

2005-11-22 Thread Mike Meyer
"[EMAIL PROTECTED]" <[EMAIL PROTECTED]> writes: > [test 1] class A: > ...i = 1 > ... a = A() A.i > 1 a.i > 1 A.i = 2 A.i > 2 a.i > 2 > > [test2] class A: > ...i = 1 > ... a = A() A.i > 1 a.i > 1 a.i = 2 A.i > 1 a.i

What a curious assignment.

2005-11-22 Thread [EMAIL PROTECTED]
[test 1] >>> class A: ...i = 1 ... >>> a = A() >>> A.i 1 >>> a.i 1 >>> A.i = 2 >>> A.i 2 >>> a.i 2 >>> [test2] >>> class A: ...i = 1 ... >>> a = A() >>> A.i 1 >>> a.i 1 >>> a.i = 2 >>> A.i 1 >>> a.i 2 >>> Is there somthing wrong -- http://mail.python.org/mailman/listinfo/python-list