1
我收到一個錯誤的Python - 屬性錯誤「_io.TextIOWrapper」對象有沒有屬性「打開」
File.open(classname+'.txt','a')
AttributeError: '_io.TextIOWrapper' object has no attribute 'open'
試圖打開一個文件。我需要打開文件並用分數寫入文件。
下面是代碼
if Exists==False:
File.open(classname+'.txt','a')
File.write(name+','+surname+','+str(1)+','+str(score)+'/n')
else:
File=open(classname+'.txt','w')
linecount=len(filelines)
for i in range(0,linecount):
File.write(filelines[i])
您說的行導致錯誤未出現在您發佈的代碼中。 –
給出完整的錯誤,包括行號,並指出它發生的位置。 –
道歉@丹尼爾,我編輯了屬性錯誤,它應該是現在它是什麼。 – UserIsMe