我需要从我调用的另一个类创建一个类的3个实例,当我遍历构造函数并使用相同的变量时,它只是初始化相同的实例而不是创建新实例。从通话中启动新实例的最佳方法是什么?
我有什么:
def loopInstances(self, x):
for b in range(3):
constructor = self.initialize(**self.kwargs) #each time this is called it does not create a new instance
constructor.call1(x)
constructor.call2(x)
我想做什么:
def loopInstances(self, x):
constructor1 = self.initialize(**self.kwargs)
constructor1.call1(x)
constructor1.call2(x)
constructor2 = self.initialize(**self.kwargs)
constructor2.call1(x)
constructor2.call2(x)
constructor3 = self.initialize(**self.kwargs)
constructor3.call1(x)
constructor3.call2(x)
更新(这可行):
d = []
for b in range(len(3)):
d.append(self.initialize(**self.kwargs))
for b in range(len(3)):
const = d[b]
const.call1(x)
const.call2(x)