Python - getline() method not printing "newlines"

117 Views Asked by At

I am relatively new to python and I am making a small game that involves importing each line of the text from a .txt file, so that it can be printed to the user. To do this, I'm using linecache.getline() to get the specific line of the file that I want while not having the whole file stored as a list. However, if I use "\n" to create a new line, then linecache.getline() automatically inserts another backslash to "cancel" it.

For example, if in the text file I write \nHello, linecache.getline() will store it in the variable as \\nHello which prints as \nHello.

Is there any way to stop this? I can post my specific code if required.

Any help with file manipulation will be appreciated since I am very new to it and thank you for looking at my question.

0

There are 0 best solutions below