Python-属性错误'_io.TextIOWrapper'对象没有属性'open' [英] Python - Attribute Error '_io.TextIOWrapper' object has no attribute 'open'
本文介绍了Python-属性错误'_io.TextIOWrapper'对象没有属性'open'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我收到一个错误
File.open(classname+'.txt','a')
AttributeError: '_io.TextIOWrapper' object has no attribute 'open'
在尝试打开文件时.我需要打开文件,然后将分数写入文件.
while trying to open a file. I need to open the file and write to the file with the scores.
这是代码
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])
推荐答案
应为
File=open(classname+'.txt','a')
File.write(name+','+surname+','+str(1)+','+str(score)+'/n')
File.close()
这篇关于Python-属性错误'_io.TextIOWrapper'对象没有属性'open'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文