Does fp.readlines() close a file?
问题 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 回答1: Once you have read