novice here.
I am trying to read lines from a file, however a single line in a .txt
file has a \n
in the middle somewhere and while trying to read that line with .readline python cuts it in the middle and outputs as two lines.
when I copy and past the line to this window, it shows up as two lines. So i uploaded the file here: https://ufile.io/npt3n
also added screenshot of the file as it shows in txt file.
- this is group chat history exported from Whatsup..if you are wondering.
- Please help me to read one line completely as shown in txt file.
.
f= open("f.txt",mode='r',encoding='utf8')
for i in range(4):
lineText=f.readline()
print(lineText)
f.close()
\n
in the middle?\n
is the thing that separates each line from the next. – Gaiser\n
as an eond of line marker. However Windows uses\r\n
, so a mere\n
does not split the line in e.g. Notepad. Maybe this question might help you with it. – Lamanna\n
,\r
and\n\r
are considered a newline. If you open the file in text-mode python will convert those 3 line-endings into just\n
. If you have to interpret the text differently you want to open the file in binary mode and handle lines by hand. – Violante