-1
내 코드는 마지막 인스턴스 만 생성합니다. len (list) 어떻게 모든 인스턴스를 분리하여 만들 수 있습니까? : | word
이 Word
의 인스턴스이라고 가정문자열 목록에서 만들기 클래스 인스턴스 목록 py2.7
@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()
이전 메모 [그의 수업] (http://stackoverflow.com/questions/9141883/convert-string-elements-to-class-attributes-py-2-7#comment11492731_9141905)에서 ID, 데이터 및 포인트를 가져옵니다. 그것의'__init__'. – DSM
@DSM은 그것이 두 배임을 알지 못했습니다. – soulcheck