drAlberT..
674
打开模式与C标准库函数完全相同fopen().
The argument mode points to a string beginning with one of the following
sequences (Additional characters may follow these sequences.):
``r'' Open text file for reading. The stream is positioned at the
beginning of the file.
``r+'' Open for reading and writing. The stream is positioned at the
beginning of the file.
``w'' Truncate file to zero length or create text file for writing.
The stream is positioned at the beginning of the file.
``w+'' Open for reading and writing. The file is created if it does not
exist, otherwise it is truncated. The stream is positioned at
the beginning of the file.
``a'' Open for writing. The file is created if it does not exist. The
stream is positioned at the end of the file. Subsequent writes
to the file will always end up at the then current end of file,
irrespective of any intervening fseek(3) or similar.
``a+'' Open for reading and writing. The file is created if it does not
exist. The stream is positioned at the end of the file. Subse-
quent writes to the file will always end up at the then current
end of file, irrespective of any intervening fseek(3) or similar.
注意:Python v3添加了许多其他模式.[链接到docs](http://docs.python.org/3.3/library/functions.html#open) (12认同)
注意到`w`和`w +`都可以做`如果文件不存在则创建文件' (4认同)
我是否正确地说,如果是`a`,`w`或`r`,`+`不会做一致的独立事情?或者我没有看到这种模式?模式是什么? (4认同)
我相信你的意思是C标准库中的fopen调用(这不是系统调用) (3认同)
在Windows上,附加到模式的`b`以二进制模式打开文件,因此还有像`rb`,`wb`和`r + b`这样的模式.Windows上的Python区分了文本和二进制文件; 读取或写入数据时,文本文件中的行尾字符会自动稍微改变. (3认同)
为什么默认的Python文档如此糟糕?https://docs.python.org/2/library/functions.html#open是否为您链接到的BSD手册页等内置函数提供了一套不错的文档? (2认同)