我的代码只创建最后一个实例乘以len(list)如何更改它以分别创建每个实例?:|
@staticmethod
def impWords():
tempFile = open('import.txt','r+')
tempFile1 = re.findall(r'\w+', tempFile.read())
tempFile.close()
for i in range(0,len(tempFile1)):
word.ID = i
word.data = tempFile1[i]
word.points = 0
Repo.words.append(word)
word.prt(word)
print str(Repo.words)
UI.Controller.adminMenu()
假设
word
是Word
的一个实例,您应该在每个迭代中创建一个新实例,如下所示:现在,如果您的
Word
类__init__
将ID
、data
和points
作为参数,并且Repo.words
是一个列表,您可以将其简化为:相关问题 更多 >
编程相关推荐