+ 3

how to append

f=open("test111.txt","a") print(f.append("samjhe")) f.close() showing: AttributeError: '_io.TextIOWrapper' object has no attribute 'append'

8th Jul 2018, 5:03 PM
Anand Agrawal
2 Answers
+ 3
this is right code. f=open(r"test111.txt","a") f.write("samjhe") f.close()
8th Jul 2018, 5:36 PM
Maninder $ingh
Maninder $ingh - avatar
+ 1
f. write() will append the text by default since you are opening the file in "a" that is append mode hence type f. write("samjhe") instead of f. append("samjhe")
8th Jul 2018, 5:36 PM
akash tambe
akash tambe - avatar