The access modes for opening python files are: "r" mode, "w" mode, "a" mode, "rb" mode, "wb" mode, "ab" mode, "r" mode, " "w" mode, "a" mode, "rb" mode, "wb" mode, "ab" mode.
Several access modes for opening python files
Access mode | Instructions |
---|---|
r | Open the file in read-only mode. The file pointer will be placed at the beginning of the file. This is the default mode. |
w | Open a file for writing only. If the file already exists, it is overwritten. If the file does not exist, create a new file. |
a | Open a file for appending. If the file already exists, the file pointer will be placed at the end of the file. In other words, new content will be written after existing content. If the file does not exist, create a new file for writing. |
rb | Open a file in binary format for reading only. The file pointer will be placed at the beginning of the file. This is the default mode. |
wb | Open a file in binary format for writing only. If the file already exists, it is overwritten. If the file does not exist, create a new file. |
ab | Open a file in binary format for appending. If the file already exists, the file pointer will be placed at the end of the file. In other words, new content will be written after existing content. If the file does not exist, create a new file for writing. |
r | Open a file for reading and writing. The file pointer will be placed at the beginning of the file. |
w | Open a file for reading and writing. If the file already exists, it is overwritten. If the file does not exist, create a new file. |
a | Open a file for reading and writing. If the file already exists, the file pointer will be placed at the end of the file. The file will be opened in append mode. If the file does not exist, a new file is created for reading and writing. |
#rb | Open a file in binary format for reading and writing. The file pointer will be placed at the beginning of the file. |
wb | Open a file in binary format for reading and writing. If the file already exists, it is overwritten. If the file does not exist, create a new file. |
ab | Open a file in binary format for appending. If the file already exists, the file pointer will be placed at the end of the file. If the file does not exist, a new file is created for reading and writing. |
Recommended learning: Python video tutorial
The above is the detailed content of What are the access modes for opening python files?. For more information, please follow other related articles on the PHP Chinese website!