you'll also want to watch for ' discussion of the file' context manager supportnew as of python and though more feature of exception processing than files themselvesit allows us to wrap file-processing code in logic layer that ensures that the file will be closed (and if neededhave its output flushed to diskautomatically on exitinstead of relying on the auto-close during garbage collectionwith open( ' :\code\data txt'as myfilefor line in myfileuse line here see for details the try/finally statement that we'll also study in can provide similar functionalitybut at some cost in extra code--three extra linesto be precise (though we can often avoid both options and let python close files for us automatically)myfile open( ' :\code\data txt'tryfor line in myfileuse line here finallymyfile close(the with context manager scheme ensures release of system resources in all pythonsand may be more useful for output files to guarantee buffer flushesunlike the more general trythoughit is also limited to objects that support its protocol since both these options require more information than we have yet obtainedhoweverwe'll postpone details until later in this book other file tools there are additionalmore specialized file methods shown in table - and even more that are not in the table for instanceas mentioned earlierseek resets your current position in file (the next read or write happens at that position)flush forces buffered output to be written out to disk without closing the connection (by defaultfiles are always buffered)and so on the python standard library manual and the reference books described in the preface provide complete lists of file methodsfor quick lookrun dir or help call interactivelypassing in an open file object (in python but not xyou can pass in the name file insteadfor more file-processing exampleswatch for the sidebar "why you will carefile scannerson page in it sketches common filescanning loop code patterns with statements we have not covered enough yet to use here alsonote that although the open function and the file objects it returns are your main interface to external files in python scriptthere are additional file-like tools in the python toolset among these tuplesfilesand everything else