eat python 003 - open mode in C and Python

Documentation for C's fopen():
---
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.

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.

======================================================

In Python: http://docs.python.org/library/functions.html#open

 

Modes 'r+' , 'w+' and 'a+' open the file for updating (note that 'w+' truncates the file). Append 'b' to the mode to open the file in binary mode, on systems that differentiate between binary and text files; on systems that don’t have this distinction, adding the 'b' has no effect.

In addition to the standard fopen() values mode may be 'U' or 'rU' . Python is usually built with universal newline support; supplying 'U' opens the file as a text file, but lines may be terminated by any of the following: the Unix end-of-line convention '/n' , the Macintosh convention '/r' , or the Windows convention '/r/n' . All of these external representations are seen as '/n' by the Python program. If Python is built without universal newline support a mode with 'U' is the same as normal text mode. Note that file objects so opened also have an attribute called newlines which has a value of None (if no newlines have yet been seen), '/n' , '/r' , '/r/n' , or a tuple containing all the newline types seen.

Python enforces that the mode, after stripping 'U' , begins with 'r' , 'w' or 'a' .

 

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值