python 中open()的用法?

open("/path/to/my/image.png", "rb") 中的‘rb’代表了什么意思?

r表示只读,b表示二进制
与此对应的是w表示可写,t表示文本方式打开。
再增加一些官方的解释:
>>> print file.__doc__
file(name[, mode[, buffering]]) -> file object

Open a file. The mode can be 'r', 'w' or 'a' for reading (default),
writing or appending. The file will be created if it doesn't exist
when opened for writing or appending; it will be truncated when
opened for writing. Add a 'b' to the mode for binary files.
Add a '+' to the mode to allow simultaneous reading and writing.
If the buffering argument is given, 0 means unbuffered, 1 means line
buffered, and larger numbers specify the buffer size. The preferred way
to open a file is with the builtin open() function.
Add a 'U' to mode to open the file for input with universal newline
support. Any line ending in the input file will be seen as a '\n'
in Python. Also, a file so opened gains the attribute 'newlines';
the value for this attribute is one of None (no newline read yet),
'\r', '\n', '\r\n' or a tuple containing all the newline types seen.
温馨提示:答案为网友推荐,仅供参考
第1个回答  2011-09-16
Python 的 open() 下。‘r’代表可读,包括 '+' 代表可读可写, 'b'代表二进制模式访问。 关于 'b' 有一点需要说明, 对于所有 POSIX 兼容的 Unix 系统(包括Linux)来说, 'b'是可由可无的, 因为它们把所有的文件当作二进制文件,包括文本文件。
第2个回答  2011-09-26
以二进制方式读取
相似回答