Python Fileinput Module Detailed

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.