File file objects are created using the open function, and the following table lists the functions commonly used by file file objects:

Serial number Method and description
1

file.close()

Close the file. The file can no longer be read and written after it is closed.

2

file.flush()

Refresh the internal buffer of the file and write the data of the internal buffer directly to the file immediately, instead of passively waiting for the output buffer to write.

3

file.fileno()

Returns an integer file descriptor FD integer that can be used on some underlying operations, such as the read method of the os module.

4

file.isatty()

If the file is connected to a terminal device, true, false is returned.

5

file.next()

Returns the next line of the file.

6

file.read([size])

Read the specified number of bytes from the file and read all if not given or negative.

7

file.readline([size])

Read the entire line, including the character """

8

file.readlines([sizehint])

Read all rows and return the list, and if you give sizeint and 0, return a row with a sum of approximately sizeint bytes, the actual read value may be larger than sizeint because the buffer needs to be filled.

9

file.seek(offset[, whence])

Set the current location of the file

10

file.tell()

Returns the current location of the file.

11

file.truncate([size])

Intercept the file, the intercepted byte is specified by size, the default is the current file location.

12

file.write(str)

Write the string to the file, returning the length of the character written.

13

file.writelines(sequence)

Write a list of sequence strings to the file, and if you need line breaks, add line breaks to each line yourself.