You can read the entire file, then slice to get a list of lines:
with open('hamlet.txt', 'r') as f:
data = f.readlines()[25:55]
if the file is large, however, it is better to skip 25 lines, then read, then exit the loop so as not to read thousands of other lines:
with open('hamlet.txt', 'r') as f:
for i, line in enumerate(hamlettext):
if i < 25:
continue
elif i >= 55:
break
else:
print(i,line.rstrip())
, , 1 ( 0, 1, enumerate(hamlettext,1), .