我希望一个类的构造函数能够构建一个可以在程序中稍后使用的第二个类的实例列表,但是只有在修改此实例列表的元素时,它才有用。正在修改全局副本,而不是第一个类的实例对象。 gc.get_objects()返回的对象是实际的Globals,还是只是副本? 我的代码:
class WireConnection:
def __init__(self, name = 'genericWire', width = 1):
self.name = name
self.width = width
self.data = [0 for x in range(width)]
self.locked = False
def WriteData(self, value, line = 0):
if not self.locked:
self.data[line] = value
return True
else: return False
def ReadData(self, line = 0):
return self.data[line]
class MainFrame:
def __init__(self, *args, **kwds):
print "Building HIRL Table"
self.hirlTable = []
for wire in gc.get_objects():
if isinstance(wire, WireConnection):
if wire.name[0:4] == "HIRL":
self.hirlTable.append(wire)
这是否能够实现我的目标?