Python uses the open method to open text files

file = open('movies.txt', 'w', encoding='utf-8')

r: Open the file in read-only mode, which means that the file content can only be read, but not written. This is the default mode.
rb: Open a file in binary read-only mode, usually used to open binary files, such as audio, pictures, videos, etc.
r+: Open a file in read-write mode, which can both read and write files.
rb+: Open a file in binary reading and writing mode. It can also be read and written, but both reading and writing are binary data.
w: Open a file for writing. If the file already exists, it is overwritten. If the file does not exist, a new file is created.
wb: Open a file in binary writing mode. If the file already exists, it is overwritten. If the file does not exist, a new file is created.
w+: Open a file for reading and writing. If the file already exists, it is overwritten. If the file does not exist, a new file is created.
wb+: Open a file in binary read-write format. If the file already exists, it is overwritten. If the file does not exist, a new file is created.
a: Open a file in append mode. 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, a new file is created to write to.
ab: Open a file in binary append mode. 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, a new file is created to write to.
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.
ab+: Open a file in binary append mode. 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.

Guess you like

Origin blog.csdn.net/rubyw/article/details/132671588