I would like to print both output in Code 3, unfortunately, it doesn't work.
Code 1
with open('file.txt') as f:
r = f.read()
print(r)
Output 1
user@linux:~$ python3 script1.py
line 1
line 2
line 3
user@linux:~$
Code 2
with open('file.txt') as f:
rs = f.read().splitlines()
print(rs)
Output 2
user@linux:~$ python3 script2.py
['line 1', 'line 2', 'line 3']
user@linux:~$
However, when I combine both codes, the second output is missing.
Code 3
with open('file.txt') as f:
r = f.read()
rs = f.read().splitlines()
print(r)
print(rs)
Output 3
user@linux:~$ python3 script3.py
line 1
line 2
line 3
[]
user@linux:~$
Why this code behave this way and how to print both of them?