Re: Class properties and object properties

2008-10-06 Thread SuperZE
TYVM Diez and Jerry Now I understand how this works -- http://mail.python.org/mailman/listinfo/python-list

Re: Class properties and object properties

2008-10-06 Thread Diez B. Roggisch
SuperZE wrote: >> 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): >> se

Re: Class properties and object properties

2008-10-06 Thread Jerry Hill
On Mon, Oct 6, 2008 at 9:38 AM, SuperZE <[EMAIL PROTECTED]> wrote: > 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 They did share it, until you assign

Re: Class properties and object properties

2008-10-06 Thread SuperZE
> 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 = [

Re: Class properties and object properties

2008-10-06 Thread Diez B. Roggisch
SuperZE wrote: > Learning python I was rewriting some of my old programs to see the > pros and cons of python when a steped in some weird (at least for me) > behavior. > > Here it is simplified > > The code: > class Test1: > myList = [4 for n in range(4)] > myInt = 4 a = Test1()

Class properties and object properties

2008-10-06 Thread SuperZE
Learning python I was rewriting some of my old programs to see the pros and cons of python when a steped in some weird (at least for me) behavior. Here it is simplified The code: >>> class Test1: myList = [4 for n in range(4)] myInt = 4 >>> a = Test1() >>> b = Test1() >>> a.myLis