我正在尝试使用从保管箱读取 csv 文件
md, res = dbx.files_download(path)
正如此链接中 所推荐的,
这是我正在尝试读取的 csv:来自csv_file_image ,我从形状丑陋的 csv 文件中获取数据。有什么方法可以像使用以下方法一样读取更多形状的数据:res.content
import csv
with open(file) as csvfile:
reader = csv.DictReader(csvfile)
for row in reader:
print(row['name'])
我想将 csv 文件作为字典读取,但我得到的只是数据为:response_data_image
我通过转换res.content
为可迭代的 obj找到了这个解决方案:
import csv
import dropbox
path = '' # file path which is needed to be read
dbx = dropbox.Dropbox('YOUR_ACCESS_TOKEN')
md, res = dbx.files_download(path)
data = res.content # data in ugly shape
# Now data is needed to be decoded from bytes to unicode and then str.split()
data = data.decode('utf-8')
data = data.split('\n')
# Now data is an iterable object, so csv.DictReader can be used
reader = csv.DictReader(data)
# Loop to get data using key value from reader dict
for row in reader:
row['nameen'] # 'nameen' is the key value in my case
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句