Python “rb”在csv文件中是什么意思?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/37729295/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
what does 'rb' mean in csv files?
提问by evtoh
import csv
with open('test.csv','rb') as file:
rows = csv.reader(file,
delimiter = ',',
quotechar = '"')
data = [data for data in rows]
This was in Python: reading in a csv file and saving columns as variables. I couldn't comment, but I'm really confused. What does 'rb' mean?
这是在Python 中:读取 csv 文件并将列保存为变量。我无法发表评论,但我真的很困惑。'rb' 是什么意思?
回答by Amin Alaee
回答by fedorqui 'SO stop harming'
From open()in the Built-in functions documentation:
从内置函数文档中的open():
open(name[, mode[, buffering]])
The most commonly-used values of mode are
'r'
for reading, (...) Thus, when opening a binary file, you should append'b'
to the mode value to open the file in binary mode, which will improve portability.
打开(名称[,模式[,缓冲]])
mode 最常用的值是
'r'
读取,(...) 因此,在打开二进制文件时,您应该附加'b'
mode 值以二进制模式打开文件,这将提高可移植性。
So this opens the file to read in a binary mode.
所以这会打开文件以二进制模式读取。