python内置函数open_python open内置函数:模式a,a +,w,w +和r +之间的区别?

本文探讨了Python的open()函数与C标准库fopen()的模式选项,包括'r', 'w', 'a', 'r+', 'w+', 'a+',解释了它们在文件操作中的行为,并提到了Windows中二进制模式的区别。同时,对Python文档质量进行了评价,并讨论了内置函数文档资源的价值。
摘要由CSDN通过智能技术生成

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认同)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值