文件对象中rb和r + b模式有什么区别? [英] What is the difference between rb and r+b modes in file objects
问题描述
#在窗口中工作..rb在Python中使用pickle模块并尝试不同的文件IO模式。
与开放(pickle_f, 'RB')作为fhand:
OBJ =和pickle.load(fhand)
#在Linux上工作。 R
与开(pickle_f, 'R')作为fhand:
OBJ =和pickle.load(fhand)
#适用于两个 R + b
与开放(pickle_f
obj = pickle.load(fhand)
从来没有读过关于R + b模式的任何地方,却发现文档在提这件事如果我使用rb,我在Linux上得到了
EOFError
。 / code>模式,如果使用r
,则在Windows上。我刚刚给了r + b
模式一个镜头,它在两者上工作。
r + b
模式? rb和r + b有什么区别?为什么当其他人不工作时,它会工作?
b
是二进制的。 r + b
模式在读取或写入模式下打开二进制文件。您可以阅读更多here 。
I am using pickle module in Python and trying different file IO modes:
# works on windows.. "rb"
with open(pickle_f, 'rb') as fhand:
obj = pickle.load(fhand)
# works on linux.. "r"
with open(pickle_f, 'r') as fhand:
obj = pickle.load(fhand)
# works on both "r+b"
with open(pickle_f, 'r+b') as fhand:
obj = pickle.load(fhand)
I never read about "r+b" mode anywhere, but found mentioning about it in the documentation.
I am getting EOFError
on Linux if I use "rb"
mode and on Windows if "r"
is used. I just gave "r+b"
mode a shot and it's working on both.
What's "r+b"
mode? What's the difference between "rb" and "r+b"? Why does it work when the others don't?
r+
is used for reading, and writing mode. b
is for binary.
r+b
mode is open the binary file in read or write mode.
You can read more here.
这篇关于文件对象中rb和r + b模式有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!