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
On Sat, Jul 2, 2011 at 2:59 PM, Saqib Ali saqib.ali...@gmail.com wrote:
snip
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
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
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):
# ...rest same
On Sat, Jul 2, 2011 at 3:23 PM, Saqib Ali saqib.ali...@gmail.com 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):
On Sun, Jul 3, 2011 at 8:23 AM, Saqib Ali saqib.ali...@gmail.com 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.
On Sat, Jul 2, 2011 at 5:46 PM, Chris Angelico ros...@gmail.com wrote:
On Sun, Jul 3, 2011 at 8:23 AM, Saqib Ali saqib.ali...@gmail.com 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
On Sun, Jul 3, 2011 at 11:07 AM, Chris Rebert c...@rebertia.com 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
--
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