+ 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.

28th Apr 2017, 1:27 PM
Khan Asfi Reza Pranto
Khan Asfi Reza Pranto - avatar
4 Respuestas
+ 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
28th Apr 2017, 1:45 PM
visph
visph - avatar
+ 1
thanks
28th Apr 2017, 1:50 PM
Khan Asfi Reza Pranto
Khan Asfi Reza Pranto - avatar
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
5th May 2017, 5:17 PM
Tommy L
Tommy L - avatar
0
lol
5th May 2017, 5:18 PM
Khan Asfi Reza Pranto
Khan Asfi Reza Pranto - avatar