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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 19:52:02  来源:igfitidea点击:

what does 'rb' mean in csv files?

pythoncsv

提问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

It means: Read the file in Binary mode.

这意味着:- [READ在文件inary模式。

For a complete list of options view this.

有关选项的完整列表,请查看

回答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.

所以这会打开文件以二进制模式读取。

回答by kylie.a

The second argument o open()is the modethe file will be opened in. 'rb'is for Read Binary mode. Read more about it here

第二个参数 oopen()mode文件将在其中打开。'rb'用于读取二进制模式。在此处阅读更多相关信息