我有两个文件并加载到类中。文件一被加载,然后创建一个字符串,然后文件二将再次加载并创建一个字符串,最后两者都在一个列表中。但是,当我调用该函数时,它只会被新文件覆盖。例如,当读取文件 2 时,它只为文件 2 创建字符串并覆盖文件 1。
class something():
def getting(self, y):# string input "0" and "1"
self.y = y #I have two files. y is a file. So if I have 2 files, then it will store 2 times into the self.y. Example, file one have "0" and "1" string
self.fun1()
def fun1(self):
self.xx = []
for i in range(2):
self.xx.append("{} and {}".format(self.y, i)) #After getting the self.y, then it will append it into self.xx.
# Example, 0 and 0 then 0 and 1; for y in "0" string.
# Next, 1 and 0 then 1 and 1; for y in "1" string
self.take()
def take(self):
return self.xx
a = ["0", "1"]
aaa = something()
for x in a:
aaa.getting(x)
print(aaa.take())
电流输出:
['1 and 0', '1 and 1']
预期的 a.take:
['0 and 0', '0 and 1', '1 and 0', '1 and 1']
达令说
相关分类