Thursday, February 11, 2016

file read in one line

output = open('pagehead.section.htm','r').read() # Not recommended in script (use in interactive mode)
 
Note: The above expression does not close the file handle, which is bad. But all file handles
are closed when the script exits. In interactive mode (command from terminal), all resources are
freed when the interpreter exits.
 
http://stackoverflow.com/questions/17577137/do-files-get-closed-during-an-exception-exit
 

No comments:

Post a Comment