当为我创建的类调用一个对象的新实例时,我的一个类的实例刚刚被覆盖。为什么会这样呢?示例如下。Python类 - 实例被覆盖?
我的类定义如下:
class my_class:
attribute = ""
examples = []
children = []
d = {}
def __init__(self, attribute, e):
self.attribute = attribute
self.examples = e
for ex in self.examples:
self.d[ex[-1]] = self.d.get(ex[-1], 0) + 1
我想提出一个初始实例为这样:
root = my_class(some_attribute, data)
然后,我创建另一个实例是这样的:
child = my_class(different_attribute, root.examples[somewhere_1:somewhere_2])
最后,我最初的'根'现在与'孩子'有些相同,'根'应该没有改变。为什么是这样!?
啊!你是对的。非常感谢你清除那个 – 2010-11-15 00:19:55