Class properties and object properties

SuperZE allansuperze at gmail.com
Mon Oct 6 09:38:27 EDT 2008


> Because you declare myList to be a *class*-level variable, which means *all*
> instances of that class (a and b in your case) *share* it. Python does not
> declare *instance* variables the way you do.
>
> Instead, do this:
>
> class Foo(object):
>     def __init__(self):
>         self.myList = []


Interesting, but that does not explain the difference in the behavior
of myList and myInt

Both were class-level variables, as far as I can see, and therefor a
and b should also share it


And good remind on default arguments :)



More information about the Python-list mailing list