【发布时间】:2017-04-25 03:54:10
【问题描述】:
我正在尝试了解如何将多行 csv 文件写入谷歌云存储。我只是没有关注documentation
靠近这里: Unable to read csv file uploaded on google cloud storage bucket
例子:
from google.cloud import storage
from oauth2client.client import GoogleCredentials
import os
os.environ['GOOGLE_APPLICATION_CREDENTIALS'] = "<pathtomycredentials>"
a=[1,2,3]
b=['a','b','c']
storage_client = storage.Client()
bucket = storage_client.get_bucket("<mybucketname>")
blob=bucket.blob("Hummingbirds/trainingdata.csv")
for eachrow in range(3):
blob.upload_from_string(str(a[eachrow]) + "," + str(b[eachrow]))
这样你就可以在谷歌云存储上找到一条线
3,c
显然它每次都会打开一个新文件并写入该行。
好的,添加一个新行 delim 怎么样?
for eachrow in range(3):
blob.upload_from_string(str(a[eachrow]) + "," + str(b[eachrow]) + "\n")
添加换行符,但再次从头开始写入。
有人可以说明这种方法是什么吗?我可以把我所有的行合并成一个字符串,或者写一个临时文件,但这看起来很丑。
也许以文件形式打开?
【问题讨论】:
-
在哪里找不到写入存储的方法?
-
请参考我在下面帖子中的回答。 stackoverflow.com/questions/54715977/…
标签: python csv google-cloud-storage