Re: Inexplicable behavior in simple example of a set in a class

2011-07-02 Thread Steven D'Aprano
Saqib Ali wrote: > I have written two EXTREMELY simple python classes. One class > (myClass1) contains a data attribute (myNum) that contains an integer. > The other class (myClass2) contains a data attribute (mySet) that > contains a set. > > I instantiate 2 instances of myClass1 (a & b). I then

Re: Inexplicable behavior in simple example of a set in a class

2011-07-02 Thread Chris Angelico
On Sun, Jul 3, 2011 at 11:07 AM, Chris Rebert wrote: > c,d >> ({}, []) > > Nasty typo in your pseudo-interpreter-session there... Whoops! This is what I get for trying to be too smart! >>> c,d ([], []) Thanks for catching that, Chris. :) (another) Chris -- http://mail.python.org/mailman/l

Re: Inexplicable behavior in simple example of a set in a class

2011-07-02 Thread Chris Rebert
On Sat, Jul 2, 2011 at 5:46 PM, Chris Angelico wrote: > On Sun, Jul 3, 2011 at 8:23 AM, Saqib Ali wrote: >> So just out of curiosity, why does it work as I had expected when the >> member contains an integer, but not when the member contains a set? > > It's not integer vs set; it's the difference

Re: Inexplicable behavior in simple example of a set in a class

2011-07-02 Thread Chris Angelico
On Sun, Jul 3, 2011 at 8:23 AM, Saqib Ali wrote: > So just out of curiosity, why does it work as I had expected when the > member contains an integer, but not when the member contains a set? It's not integer vs set; it's the difference between rebinding and calling a method. It's nothing to do wi

Re: Inexplicable behavior in simple example of a set in a class

2011-07-02 Thread Chris Rebert
On Sat, Jul 2, 2011 at 3:23 PM, Saqib Ali wrote: >> Instance variables are properly created in the __init__() >> initializer method, *not* directly in the class body. >> >> Your class would be correctly rewritten as: >> >> class MyClass2(object): >>     def __init__(self): >>         self.mySet =

Re: Inexplicable behavior in simple example of a set in a class

2011-07-02 Thread Saqib Ali
> Instance variables are properly created in the __init__() > initializer method, *not* directly in the class body. > > Your class would be correctly rewritten as: > > class MyClass2(object): >     def __init__(self): >         self.mySet = sets.Set(range(1,10)) > >     def clearSet(self): > # ...r

Re: Inexplicable behavior in simple example of a set in a class

2011-07-02 Thread Peter Otten
Saqib Ali wrote: > > > I have written two EXTREMELY simple python classes. One class > (myClass1) contains a data attribute (myNum) that contains an integer. > The other class (myClass2) contains a data attribute (mySet) that > contains a set. > > I instantiate 2 instances of myClass1 (a & b).

Re: Inexplicable behavior in simple example of a set in a class

2011-07-02 Thread Chris Rebert
On Sat, Jul 2, 2011 at 2:59 PM, Saqib Ali wrote: > Then I instantiate 2 instances of myClass2 (c & d). I then change the > value of c.mySet. Bizarrely changing the value of c.mySet also affects > the value of d.mySet which I haven't touched at all!?!?! Can someone > explain this very strange beha

Inexplicable behavior in simple example of a set in a class

2011-07-02 Thread Saqib Ali
I have written two EXTREMELY simple python classes. One class (myClass1) contains a data attribute (myNum) that contains an integer. The other class (myClass2) contains a data attribute (mySet) that contains a set. I instantiate 2 instances of myClass1 (a & b). I then change the value of a.myNum