Member variable in object spontaneously turns to None
Norbert
norbulus at hotmail.com
Sat Nov 9 23:46:20 EST 2002
I am encountering a strange problem where some member variables,
initialized upon instantiation of the object they are contained in,
suddenly appear as having the value 'None' when I try to access them.
Other member variables in the affected object are unchanged.
class Foo:
def __init__(self):
self.bar = 0
self.x = 0
self.y = 'a'
matrix = []
for i in range(10):
row = []
for j in range(10):
row.append(Foo())
matrix.append(row)
print "%d" % matrix[0][0].bar
0
print "%d" % matrix[0][0].x
0
....
print "%d" % matrix[1][1].bar
0
print "%d" % matrix[1][1].x
None
I am perplexed. Any help would be appreciated. Thanks.
More information about the Python-list
mailing list