In python I'm seeing evidence that fp.readlines() is closing the file when I try to access the fp later in the program. Can you confirm this behavior, do I need to re-open the file again later if I also want to read from it again?
Is the file closed? is similar, but didn't answer all of my questions.
import sys def lines(fp): print str(len(fp.readlines())) def main(): sent_file = open(sys.argv[1], "r") lines(sent_file) for line in sent_file: print line this returns:
20
withstatement.print fp.closedtells you if it is closed or notseekmethod can also be used to reset the file pointer to some place earlier than the end of the file, if the file object is seekable (typically, real files are seekable, pipelines are not).