Is it possible to read in from a text file a set line range for example from line 20 to 52?
I am opening the file and reading the file like this:
te
You can do two things. You can use enumerate(), and use an if statement:
text_file = open(file_to_save, "r")
lines = []
for index, text in enumerate(text_file):
if 19 <= index <= 51:
lines.append(text)
Or instead, you can use readlines() and then slice:
text_file = open(file_to_save, "r")
lines = text_file.readlines()
lines = lines[19:52]