Answer the question
In order to leave comments, you need to log in
How to list all lines from a file?
I can't figure out how to list all lines from a file?
I found such a method, but it reads the file line by line, and I need to open the file, read its contents into a variable (about 200 lines) and close it, then work with this variable.
Since the process there will be long, and you will not have to keep the file open.
for x in open("DATA.txt", "r").readlines():
print(x)
Answer the question
In order to leave comments, you need to log in
with open("DATA.txt") as file:
lines = file.read().splitlines()
for line in lines:
print(line)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question