Latest web development tutorials

Python3 File Method

file functions to create objects using open, the following table lists the file objects commonly used functions:

No. Method and Description
1

file.close ()

Close the file. Close the file can no longer read and write operations.

2

file.flush ()

Internal refresh file buffering, the data directly to the internal buffer written to the file immediately, rather than passively waiting for output buffer written.

3

file.fileno ()

Return an integer file descriptor (file descriptor FD integer), it can be used in such a method os module read some of the underlying operations.

4

file.isatty ()

If the file is connected to a terminal device returns True, otherwise False.

5

file.next ()

Returns the file the next line.

6

file.read ([size])

Reads the specified number of bytes from the file, if not given or is negative read all.

7

file.readline ([size])

Read the entire line, including the "\ n" character.

8

file.readlines ([sizehint])

Read all rows and return a list, if given sizeint> 0, returns the sum of approximately sizeint byte row of the actual read value may be higher than sizhint larger, because of the need to fill the buffer.

9

file.seek (offset [, whence])

Current position settings file

10

file.tell ()

Returns the current file position.

11

file.truncate ([size])

Intercept file intercepted by byte size specified, it defaults to the current file position.

12

file.write (str)

The string to the file, there is no return value.

13

file.writelines (sequence)

Write a list of strings to the file sequence, if you need to change the line will have its own line breaks added for each row.