"[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
> 2
>>>>
>
> Is there somthing wrong????

No. Reading a.i looks up i by checking the instance (a), then the
class (A), so a.i and A.i are the same thing. So changing A.i changes
the value seen by a.i. Binding a.i binds i to a, not A, so after the
binding, a.i and A.i are different things.

         <mike
-- 
Mike Meyer <[EMAIL PROTECTED]>                  http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to