+ 3
How to add a new line in a text file?and I am facing a problem
i am making program . i am facing a problem. user=input("Username:") i=open("name.txt","w") i.write(user+"/n") i.close() when i opened the code first time i wrote-Pranto..the text file also wrote Pranto.but when I again opened the code and wrote-Asfi. in the text file, pranto get disappeard and there was only Asfi.Pranto was totally removed from the text file. So what can i do that ithe text file will contain all the names that i will write and none of them will be removed.
4 Respostas
+ 6
Open your file with the append mode ( 'a' ):
user=input("Username:")
i=open("name.txt","a")
i.write(user+"/n")
i.close()
http://www.pythonforbeginners.com/files/reading-and-writing-files-in-JUMP_LINK__&&__python__&&__JUMP_LINK
+ 1
thanks
0
when u are in python's console @ sololearn, just use this cheat, it will acquire your PC extra RAM:
import os
import sys
print(os.getcwd())
print(os.listdir())
with open('PolandHacks.txt', 'w+') as f:
f.write('Pyjerdole policje i zlodzieji z wiejskiej - Z. Stonoga')
file = open('PolandHacks.txt', 'r')
print(file.read())
file.close()
But dont run it 2 times in a row, it might blow up ur LG Screen
0
lol