Python file functions

Source: Internet
Author: User

Method actions for File objects

File.close () Close file

File.fileno () returns the descriptor of the document (file descriptor, FD, integer value)

File.flush () flush the internal buffer of the file

File.isatty () Determine if file is a class TTY device

File.nexta () returns the next line of the file (similar to File.readline ()), or when there are no other rows

Throw Stopiteration exception

File.read (Size=-1) reads a size byte from a file, and when no size or given negative value is given, the read

Take all the remaining bytes and return as a string

File.readintob (buf, size) reads a size byte from a file to the BUF buffer (not supported)

File.readline (Size=-1) reads from the file and returns one row (including the line terminator), or returns the maximum size

of characters

File.readlines (sizhint=0) reads all the lines of the file and returns as a list (containing all the line ends

characters); If the given Sizhint is greater than 0, then the sum is returned about

The sizhint byte of the row (size is determined by the next value of the buffer capacity) (

If the buffer size can only be a multiple of 4K, if the Sizhint is 15k, then

The last possible return is 16k ——— Translator Press)

File.xreadlinesc () a more efficient way to iterate and replace ReadLines ()

File.seek (off, whence=0) moves the file pointer in the file, from whence (0 for the file, 1 generations

Table current position, 2 for end of file) offset off byte

File.tell () returns the current position in the file

File.truncate (Size=file.tell ()) intercepts the file to the maximum size byte, which defaults to the current file location

File.write (str) writes a string to a file

File.writelines (SEQ) writes a string sequence seq to a file; The SEQ should be a return string

An iterative object; Before 2.2, it was just a list of strings


This article is from the "Eight Miles" blog, so be sure to keep this source http://5921271.blog.51cto.com/5911271/1723300

Python file functions

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.