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
"[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
[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
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
[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
"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
[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
> >>
"[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
[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