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