Python's Fileinput module allows you to quickly iterate through one or more files.
Import Fileinput for inch fileinput.input (): process (line)
Fileinput.input ([files[, inplace[, backup[, bufsize[, mode[, Openhook]] []]
Files: A list of paths to the file
InPlace: Whether to return output to the original file, default to 0 does not return, set to 1 o'clock return
Backup: The extension of the backed-up file
BufSize: Buffer size, python2. 7. Version 12 This parameter is no longer used
Mode: Reading, writing, read/write, binary four mode, default is read mode
Openhook: This parameter must be a function with two parameters (file name and pattern)
Fileinput.filename () # Returns the name of the file that is currently being read
Fileinput.fileno ()#returns the integer "file descriptor" of the current fileFileinput.lineno ()#returns the cumulative line number of the row just readFileinput.filelineno ()#returns the line number in the current fileFileinput.isfirstline ()#determines whether the read line is the first line of the file, returns True, otherwise falseFileinput.isstdin ()#determines whether the last line of Sys.stdin is read, returns True, otherwise falseFileinput.nextfile ()#closes the current file so that the next iteration reads the first line of the next file (if any)fileinput.close ()#Close File Queue
Python Fileinput Module Detailed