Z
Zhao Huang
Hi,
I'm new to python and I've come across a problem with my objects
corrupting each other.
class aclass:
num = 0
l = [[],[]]
a = aclass()
b = aclass()
a.l.append(1)
print "a.l",a.l
print "b.l",b.l
My expectation is that a,b are separate objects, but appending to
a's l also appends to b's l. Why does this occur? On the other hand,
the command
a.num = 1
doesn't change b.num's. This is inconsistency is driving me crazy.
What am I doing wrong?
Thanks for any help
I'm new to python and I've come across a problem with my objects
corrupting each other.
class aclass:
num = 0
l = [[],[]]
a = aclass()
b = aclass()
a.l.append(1)
print "a.l",a.l
print "b.l",b.l
My expectation is that a,b are separate objects, but appending to
a's l also appends to b's l. Why does this occur? On the other hand,
the command
a.num = 1
doesn't change b.num's. This is inconsistency is driving me crazy.
What am I doing wrong?
Thanks for any help