Python-open()的模式

open(file, mode='r', buffering=-1, encoding=None, errors=None, newline=None, closefd=True, opener=None)    

The available modes are:

========= ===============================================================
Character Meaning
--------- ---------------------------------------------------------------
'r' open for reading (default)                                                          只读 【open()函数的默认模式】
'w' open for writing, truncating the file first                                    首先清空文件,然后写
'x' create a new file and open it for writing                                    新建一个文件并且可以写入
'a' open for writing, appending to the end of the file if it exists      不清空,写为追加
'b' binary mode                                                                              二进制模式【不是很明白】
't' text mode (default)                                                                     文本模式(默认) 
'+' open a disk file for updating (reading and writing)                    打开文件进行读写
========= ===============================================================

补充:

r+:可读可写,若文件不存在,报错

w+: 可读可写,若文件不存在,创建

版权声明:本文为博主原创文章,遵循 CC 4.0 by-sa 版权协议,转载请附上原文出处链接和本声明。

https://blog.csdn.net/py_tester/article/details/78347602

原文地址:https://www.cnblogs.com/ohlala/p/11389220.html