How to make a newline in .txt from user input? | Sololearn: Learn to code for FREE!
0

How to make a newline in .txt from user input?

I take a string to be saved in .txt from user. However, when I give my string like that "Line1\nLine2\nLine3" and write this to the file, it writes the string to the first line as it is. How can I make it so it makes a newline whenever it encounters "\n" ? Edit: When I give my string like that to the function explicitly ( and not by an argument ), file.write("Line1\nLine2") It makes the newlines

23rd Jun 2020, 1:34 PM
Mustafa K.
Mustafa K. - avatar
2 Respostas
+ 6
Before writing input string to file replace "\\n" by "\n". text = input() text = text.replace("\\n","\n") #write `text` to file.
23rd Jun 2020, 1:49 PM
ūüáģūüá≥OmkarūüēČ
ūüáģūüá≥OmkarūüēČ - avatar
+ 8
Please show us your code. Put it in playground and link it here. Thanks!
23rd Jun 2020, 1:50 PM
Lothar
Lothar - avatar