{
    "mode": "pydoc",
    "parameter": "fileinput",
    "section": "",
    "url": "https://www.chedong.com/phpMan.php/pydoc/fileinput/json",
    "generated": "2026-11-29T16:07:36Z",
    "sections": {
        "NAME": {
            "content": "fileinput - Helper class to quickly write a loop over all standard input files.\n",
            "subsections": []
        },
        "MODULE REFERENCE": {
            "content": "https://docs.python.org/3.12/library/fileinput.html\n\nThe following documentation is automatically generated from the Python\nsource files.  It may be incomplete, incorrect or include features that\nare considered implementation detail and may vary between Python\nimplementations.  When in doubt, consult the module reference at the\nlocation listed above.\n",
            "subsections": []
        },
        "DESCRIPTION": {
            "content": "Typical use is:\n\nimport fileinput\nfor line in fileinput.input(encoding=\"utf-8\"):\nprocess(line)\n\nThis iterates over the lines of all files listed in sys.argv[1:],\ndefaulting to sys.stdin if the list is empty.  If a filename is '-' it\nis also replaced by sys.stdin and the optional arguments mode and\nopenhook are ignored.  To specify an alternative list of filenames,\npass it as the argument to input().  A single file name is also allowed.\n\nFunctions filename(), lineno() return the filename and cumulative line\nnumber of the line that has just been read; filelineno() returns its\nline number in the current file; isfirstline() returns true iff the\nline just read is the first line of its file; isstdin() returns true\niff the line was read from sys.stdin.  Function nextfile() closes the\ncurrent file so that the next iteration will read the first line from\nthe next file (if any); lines not read from the file will not count\ntowards the cumulative line count; the filename is not changed until\nafter the first line of the next file has been read.  Function close()\ncloses the sequence.\n\nBefore any lines have been read, filename() returns None and both line\nnumbers are zero; nextfile() has no effect.  After all lines have been\nread, filename() and the line number functions return the values\npertaining to the last line read; nextfile() has no effect.\n\nAll files are opened in text mode by default, you can override this by\nsetting the mode parameter to input() or FileInput.init().\nIf an I/O error occurs during opening or reading a file, the OSError\nexception is raised.\n\nIf sys.stdin is used more than once, the second and further use will\nreturn no lines, except perhaps for interactive use, or if it has been\nexplicitly reset (e.g. using sys.stdin.seek(0)).\n\nEmpty files are opened and immediately closed; the only time their\npresence in the list of filenames is noticeable at all is when the\nlast file opened is empty.\n\nIt is possible that the last line of a file doesn't end in a newline\ncharacter; otherwise lines are returned including the trailing\nnewline.\n\nClass FileInput is the implementation; its methods filename(),",
            "subsections": [
                {
                    "name": "lineno",
                    "content": "correspond to the functions in the module.  In addition it has a"
                },
                {
                    "name": "readline",
                    "content": "getitem() method which implements the sequence behavior.  The\nsequence must be accessed in strictly sequential order; sequence\naccess and readline() cannot be mixed.\n\nOptional in-place filtering: if the keyword argument inplace=1 is\npassed to input() or to the FileInput constructor, the file is moved\nto a backup file and standard output is directed to the input file.\nThis makes it possible to write a filter that rewrites its input file\nin place.  If the keyword argument backup=\".<some extension>\" is also\ngiven, it specifies the extension for the backup file, and the backup\nfile remains around; by default, the extension is \".bak\" and it is\ndeleted when the output file is closed.  In-place filtering is\ndisabled when standard input is read.  XXX The current implementation\ndoes not work for MS-DOS 8+3 filesystems.\n"
                }
            ]
        },
        "CLASSES": {
            "content": "builtins.object\nFileInput\n",
            "subsections": [
                {
                    "name": "class FileInput",
                    "content": "|  FileInput(files=None, inplace=False, backup='', *, mode='r', openhook=None, encoding=None, errors=None)\n|\n|  FileInput([files[, inplace[, backup]]], *, mode=None, openhook=None)\n|\n|  Class FileInput is the implementation of the module; its methods\n|  filename(), lineno(), fileline(), isfirstline(), isstdin(), fileno(),\n|  nextfile() and close() correspond to the functions of the same name\n|  in the module.\n|  In addition it has a readline() method which returns the next\n|  input line, and a getitem() method which implements the\n|  sequence behavior. The sequence must be accessed in strictly\n|  sequential order; random access and readline() cannot be mixed.\n|\n|  Methods defined here:\n|\n|  del(self)\n|\n|  enter(self)\n|\n|  exit(self, type, value, traceback)\n|\n|  init(self, files=None, inplace=False, backup='', *, mode='r', openhook=None, encoding=None, errors=None)\n|      Initialize self.  See help(type(self)) for accurate signature.\n|\n|  iter(self)\n|\n|  next(self)\n|\n|  close(self)\n|\n|  filelineno(self)\n|\n|  filename(self)\n|\n|  fileno(self)\n|\n|  isfirstline(self)\n|\n|  isstdin(self)\n|\n|  lineno(self)\n|\n|  nextfile(self)\n|\n|  readline(self)\n|\n|  ----------------------------------------------------------------------\n|  Class methods defined here:\n|\n|  classgetitem = GenericAlias(...)\n|      Represent a PEP 585 generic type\n|\n|      E.g. for t = list[int], t.origin is list and t.args is (int,).\n|\n|  ----------------------------------------------------------------------\n|  Data descriptors defined here:\n|\n|  dict\n|      dictionary for instance variables\n|\n|  weakref\n|      list of weak references to the object\n"
                }
            ]
        },
        "FUNCTIONS": {
            "content": "",
            "subsections": [
                {
                    "name": "close",
                    "content": "Close the sequence.\n"
                },
                {
                    "name": "filelineno",
                    "content": "Return the line number in the current file. Before the first line\nhas been read, returns 0. After the last line of the last file has\nbeen read, returns the line number of that line within the file.\n"
                },
                {
                    "name": "filename",
                    "content": "Return the name of the file currently being read.\nBefore the first line has been read, returns None.\n"
                },
                {
                    "name": "fileno",
                    "content": "Return the file number of the current file. When no file is currently\nopened, returns -1.\n"
                },
                {
                    "name": "hook_compressed",
                    "content": ""
                },
                {
                    "name": "hook_encoded",
                    "content": ""
                },
                {
                    "name": "input",
                    "content": "Return an instance of the FileInput class, which can be iterated.\n\nThe parameters are passed to the constructor of the FileInput class.\nThe returned instance, in addition to being an iterator,\nkeeps global state for the functions of this module,.\n"
                },
                {
                    "name": "isfirstline",
                    "content": "Returns true the line just read is the first line of its file,\notherwise returns false.\n"
                },
                {
                    "name": "isstdin",
                    "content": "Returns true if the last line was read from sys.stdin,\notherwise returns false.\n"
                },
                {
                    "name": "lineno",
                    "content": "Return the cumulative line number of the line that has just been read.\nBefore the first line has been read, returns 0. After the last line\nof the last file has been read, returns the line number of that line.\n"
                },
                {
                    "name": "nextfile",
                    "content": "Close the current file so that the next iteration will read the first\nline from the next file (if any); lines not read from the file will\nnot count towards the cumulative line count. The filename is not\nchanged until after the first line of the next file has been read.\nBefore the first line has been read, this function has no effect;\nit cannot be used to skip the first file. After the last line of the\nlast file has been read, this function has no effect.\n"
                }
            ]
        },
        "DATA": {
            "content": "all = ['input', 'close', 'nextfile', 'filename', 'lineno', 'fileli...\n",
            "subsections": []
        },
        "FILE": {
            "content": "/usr/lib/python3.12/fileinput.py\n\n",
            "subsections": []
        }
    },
    "summary": "fileinput - Helper class to quickly write a loop over all standard input files.",
    "flags": [],
    "examples": [],
    "see_also": []
}