problem with classes

cfgauss cfgauss at u.washington.edu
Fri Aug 26 06:19:15 EDT 2005


I am having a strange problem with classes.  I'm fairly sure the
problem is with classes, anyway, because when I re-write the program
without them, it works like I'd expect it to.

When I run this program, at first, L[0].z[1] is 0, because z=[0,0].
But after I run that loop to assign different values to L[1].z[0] and
L[1].z[1], somehow the value of L[0].z[1] has changed to 1.  I have no
idea why this is happening, can anyone help me?

class Stuff:
    z=[0,0]

L = [Stuff(),Stuff()]
print "L[0].z[1]=%i" % L[0].z[1]
for j in range(2):
    L[1].z[j] = j
print "L[0].z[1]=%i" % L[0].z[1]




More information about the Python-list mailing list