簡體   English   中英

讀取 s3 中的 csv 文件

[英]Read through csv file in s3

我正在嘗試讀取 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?)                                                           

刪除字節( 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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM