fileinput

The fileinput module iterates over a list of input files and reads their contents line by line. The main interface to the module is the following function:


input([files [, inplace [, backup]]])

Creates an instance of the FileInput class. files is an optional list of filenames to be read (a single filename is also permitted). If omitted, the filenames are read from the command line in sys.argv[1:]. An empty list implies input from stdin, as does a filename of '-'. If inplace is set to True, each input file is moved to a backup file and sys.stdout is redirected to overwrite the original input file. The backup file is then removed when the output is closed. The backup option specifies a filename extension such as .bak that is appended ...

Get Python: Essential Reference, Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.