【发布时间】:2018-08-01 05:18:05
【问题描述】:
我有以下代码:
class PWA_Parse():
include = []
def appendInclude(self, element):
self.include.append(element)
def printMemory(self):
print "Class location", hex(id(self)), "List location:", hex(id(self.include))
a = PWA_Parse()
b = PWA_Parse()
a.appendInclude(5)
a.printMemory()
b.printMemory()
两者的列表内存地址相同:
Class location 0x29e9788 List location: 0x29e95d0
Class location 0x29e97b0 List location: 0x29e95d0
如何在类定义中创建一个列表以便在实例化时获得两个单独的列表? (提示:我已经用 list() 试过了)
【问题讨论】: