class test:
defaultsclass = {'x': ['xxx'],
'y': ['yyy']}
def __init__(self):
for k, v in self.defaultsclass.items():
print 'setting from class table: ' + k + ':' +
str(v)
self.__dict__[k] = v
def __str__(self):
return str([k + ':' + str(v) for k, v in self.__dict__.
items()])
print 'start'
t = test()
t.x.append('123')
t.y.append('123')
print 't:\n%s' % t
print 'defaultsclass'
for k, v in test.defaultsclass.items():
print 'k: %s; v:%s' % (k, str(v))
********result*************
start
setting from class table: y:['yyy']
setting from class table: x:['xxx']
t:
["y:['yyy', '123']", "x:['xxx', '123']"]
defaultsclass
k: y; v:['yyy', '123']
k: x; v:['xxx', '123']
***************************
I don't see any code which modifies the defaultsclass
dictionary (a class variable?) but it is clearly getting
modified. Is there something I don't understand here?
|