Reading and writing files is the most basic operation , stay UNIX In the system , All the objects of operation can be viewed as files , Everything is a document , Whether it's a disk file object , Or peripheral objects . Whether it's the actual document , Or virtual memory devices . You can see at the operating system level , It defines the document as the standard operation standard , So understand the operation of the file , Or the operation process , We can think that we have made a deep understanding of this programming paradigm . File is an abstraction of the device from the system , It is also a design of the system at a higher level .
Python Read the file , Generally, there are two kinds of documents , One is to read and write files , One is to read and write binary files . adopt Open Function to open the stream associated with the file , And then complete the operation of reading or writing data .open The function is defined as follows ：
open(file, mode='r', buffering=-1, encoding=None, errors=None, newline=None, closefd=True, opener=None)
file Parameter specifies the name of the file to be processed .mode Parameters define the operation mode of the file stream , For specific values, please refer to the table below ：