TYVM Diez and Jerry
Now I understand how this works
--
http://mail.python.org/mailman/listinfo/python-list
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
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
> 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 = [
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()
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