fileinput.input()

fileinput.input(files=None, inplace=False, backup='', bufsize=0, mode='r', openhook=None)

Create an instance of the FileInput class. The instance will be used as global state for the functions of this module, and is also returned to use during iteration. The parameters to this function will be passed along to the constructor of the FileInput class.

The FileInput instance can be used as a context manager in the with statement. In this example, input is closed after the with statement is exited, even if an exception occurs:

with fileinput.input(files=('spam.txt', 'eggs.txt')) as f:
    for line in f:
        process(line)

Changed in version 3.2: Can be used as a context manager.

Changed in version 3.5.2: The bufsize parameter is no longer used.

doc_python
2016-10-07 17:33:12
Comments
Leave a Comment

Please login to continue.