Skip to content Skip to sidebar Skip to footer

Python - Attribute Error '_io.textiowrapper' Object Has No Attribute 'open'

I receive an error 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 writ

Solution 1:

it should be

File=open(classname+'.txt','a')
File.write(name+','+surname+','+str(1)+','+str(score)+'/n')
File.close()

Solution 2:

The problem is that at the beginning you declare

File=open(classname+'.txt','r+')

and then you ask again to open File

File.open(classname+'.txt','a')

but File is already open(classname+'.txt','r+'). Just skip File.open(classname+'.txt','a') and it should work fine.

Post a Comment for "Python - Attribute Error '_io.textiowrapper' Object Has No Attribute 'open'"