N
N
nzarchii602020-05-02 10:18:51
Python
nzarchii60, 2020-05-02 10:18:51

Line break character newline \n python?

Good afternoon.
I am writing because I can no longer flog with some anomalies, forcibly popping up.
DURING the construction of the architecture, I observed that when outputting text to a line from

var1 = 'text \n terron \n rerty'
print(var1)
text
terron retry


I want to implement such only the value of the variable I get from the txt file.
first line starts with 'text \n terron \n rerty'
f = open("FILE.txt", 'r+', encoding = 'utf-8')
tect = f.readline()
text = tect
print(str(text))
'text \n terron \n rerty'

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander, 2020-05-02
@nzarchii60

\n is the interpreter's way of encoding the line break character in text file values. The strings are already converted in memory.
try
text = tect.replace("\\n","\n")

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question