File objects supply all the minimal indispensable functionality needed for file I/O. Some auxiliary Python library modules, however, offer convenient supplementary functionality, making I/O even easier and handier in several important cases.
fileinput module lets you loop over all the lines in a list of text files. Performance is good, comparable to the performance of direct iteration on each file, since
fileinput uses buffering to minimize I/O. You can therefore use module
fileinput for line-oriented file input whenever you find the module’s rich functionality convenient, with no worries about performance. The
input function is the key function of module
fileinput, and the module also provides a
FileInput class whose methods support the same functionality as the module’s functions.
Closes the whole sequence so that iteration stops and no file remains open.
Creates and returns an instance
Returns the number of lines read so far from the file now being read. ...