Python advanced articles
File and IO
1. Basic file operations
When using a file object, you first need to create a file object through the built-in open() method, and then perform some basic file operations through the methods provided by the object.
-
1. Create and open files
-
open()
Open file and create file object
file = open(filename, mode, buffering)
file: the file object to be created
filename: the file name of the file to be created or opened must be enclosed in single or double quotation marks. The file to be opened is at the current location, so there is no need to use an absolute path, otherwise it will be used.
mode: Optional parameter, used to specify the file opening mode. Specific page P203
buffering: Optional parameter, used to specify the buffer mode for reading and writing files. 0, do not cache; 1, cache; greater than 1, indicate the buffer size. The default is cache mode.-
1.file = open(“status.txt”)
-
-