I am working on a project and want to print multiple lines in a text file. This is the method I used for this purpose.
def story_part(file_path,initial_index,final_index):
line_number = list(range((initial_index -1) ,final_index ))
mylines = []
with open(file_path) as f:
for i , line in enumerate(f):
if i in line_number:
mylines.append(line.rstrip())
elif i > final_index:
break
for content in mylines:
print(content)
can you type more efficient code?
I was trying to print in a specified portion from a text file. I have searched through several websites and didn't find something helpful.
and after scratching for some time, I come up with this function. Is this the correct way, or you can help it to improve?