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
2 Réponses
+ 6
Before writing input string to file replace "\\n" by "\n".
text = input()
text = text.replace("\\n","\n")
#write `text` to file.
+ 8
Please show us your code. Put it in playground and link it here. Thanks!