猿问

通读 s3 中的 csv 文件

我正在尝试读取s3存储桶中的csv文件,但出现错误。似乎有问题。list()


import csv

import s3fs

fs = s3fs.S3FileSystem(key='key', token='token', secret='secret')

def open_csv():

    with fs.open('way/to/my.csv', 'rb') as csv_file:

        csv_reader = list(csv.reader(csv_file))

        return csv_reader

原木:


csv_reader = list(csv.reader(csv_file))

_csv.Error: iterator should return strings, not bytes (did you open the file in text mode?)                                                           



喵喔喔
浏览 120回答 1
1回答

哈士奇WWW

删除字节(b)用:def open_csv():    with fs.open('way/to/my.csv', 'r') as csv_file:        csv_reader = list(csv.reader(csv_file))        return csv_reader
随时随地看视频慕课网APP

相关分类

Python
我要回答