0

Let's say I have an example file named 'greetings.txt' with this in it

Hello\nThere

and this code

f = open("greetings.txt", "r")
readit = f.read()
print(readit)

But the output is

Hello\nThere

What do I do to make the output detect the "\n" and put Word "There" to the 2nd line?

Thanks for your answers!

Kewbin
  • 3
  • 1
  • 4

1 Answers1

1

Try this:

print(readit.replace(r'\n','\n'))

(When an 'r' or 'R' prefix is present, a character following a backslash is included in the string without change, and all backslashes are left in the string. See here)

mshsayem
  • 17,557
  • 11
  • 61
  • 69