Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 write to the file with the scores.

Here is the code

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])
like image 338
Klodiano Avatar asked May 24 '26 12:05

Klodiano


1 Answers

it should be

File=open(classname+'.txt','a')
File.write(name+','+surname+','+str(1)+','+str(score)+'/n')
File.close()
like image 187
The6thSense Avatar answered May 27 '26 02:05

The6thSense



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!