Open (file, mode= ' R ', Buffering=-1, Encoding=none, Errors=none, Newline=none, Closefd=true, Opener=none):
In the use of this function, in addition to the file parameter must be filled out, other parameters can be selected. The default values are used in this code for other parameters.
When using open (), if the file does not exist, the ioerror will be returned.
Parameter description:
File: Document name;
Mode: The way the file is opened, the function provides the following way, where ' RT ' is the default way.
' R ' Open for reading (default)--read-only, defaults
' W ' open for writing, truncating the file first--writes, overwrites the source content
The ' x ' Create a new file and open it for writing--creates a novel and writes the content, if the file already exists, an error will be made: Fileexistserror
' A ' open for writing, appending to the end of the file if it exists--write, append write at the end if the files have content
' B ' binary mode--binary mode
' t ' text mode (default)--Text pattern
' + ' open a disk file for updating (reading and writing)--Update disk files, read and write
' U ' universal newline mode (deprecated)--deprecated in Paython3
Buffering: Used to set the cache policy
In binary mode, the buffer is toggled using the% of N, and in text mode, the row buffer (fixed size buffer area) is represented by 1.
When parameters are not given, the buffer size of the binary file is determined by the underlying device and can be via IO. Default_buffer_size obtained, usually 4096 or 8192 bytes
The text file uses row buffering.
Encoding: Encoding or decoding mode. The default encoding method depends on the platform, if you need special settings, you can refer to the codecs module, get the list of encodings.
Errors: optional, and cannot be used in binary mode, specifies how encoding errors are handled, and can be codecs. Codec getting the encoding error string
NewLine: Line control, parameters are: None, ' \ n ', ' \ R ', ' \ r \ n '.
Input, if the parameter is none, then the end of the line flag can be: ' \ n ', ' \ R ', ' \ r \ n ' any one, and the three control will first be converted to: ' \ n ' before it is called;
If the argument is ', all common wrap-end flags can be used, but the line-end identifier return call is not encoded.
Output, if the parameter is none, then the end of the line flag can be: ' \ n ' is converted to the system default delimiter, if it is ', ' \ n ' will not be encoded.
Closefd:false: The underlying file descriptor is still open when the file is closed, this is not allowed, so it needs to be set to Ture
Opener: You can use a custom opener by calling the *opener* method. The underlying file descriptor is obtained by calling *opener* or *file*, *flags*.
*opener* must return an open file description. Os.open as a result of *opener*, functionally, similar to pass none.
Original: 78808779
Python3 open () function parameters