Reputation: 127
I have this line in a .txt file:
I just got home.\nDid you make lunch?\nOh, I see...
It's just one line, it's formatted like this for a game, so it is exactly like this, with the \n's.
What I need is that when I print this, after I store it into a variable or list, to print it on multiple lines, respecting the \n. Like this:
I just got home.\n
Did you make lunch?\n
Oh, I see...
I can't think of a way to modify the output to make a new line after the program displays each \n. How would I do this?
Upvotes: 1
Views: 69
Reputation: 92854
Using of str.replace()
function would be enough:
s="I just got home.\nDid you make lunch?\nOh, I see..."
print(s.replace("\n", "\\n\n"))
The output:
I just got home.\n
Did you make lunch?\n
Oh, I see...
Upvotes: 1