Using Python, how do I print the lines of a text file, given a starting and ending line number?
I have come up with a function, but this doesn’t work.
def printPart(src, des, varFile):
returnLines = ""
for curLine in range(src, des):
returnLines += linecache.getline(varFile, curLine)
return returnLines
Since file objects are iterable in Python, you can apply all the functions from
itertoolsto them. Have a look atitertools.islice(). (Since this is homework, I’ll leave the details to you.)