我需要在Google云端存储中的存储区中写入MySQL ina csv格式的结果集。将MySQL结果写入Google云端存储中的CSV文件
依照指示操作,here,我创建了下面的示例代码:
import cloudstorage
from google.appengine.api import app_identity
import db # My own Mysql wrapper
dump = db.get_table_dump(schema) # Here I made a simples SQL SELECT and fetchall()
bucket_name = app_identity.get_default_gcs_bucket_name()
file_name = "/" + bucket_name + "/finalfiles/" + schema + "/" +"myfile.csv"
with cloudstorage.open(file_name, "w") as gcsFile:
gcsFile.write(dump)
它没有工作“的原因write
需要一个字符串参数和dump
是元组的元组从fetchall()
结果。
我不能使用this approach(或类似的),因为我不能在GAE环境中编写文件,而且由于我的结果集的大小,我也不能从元组中创建CSV字符串,如here(实际上,我尝试了它,它需要很长时间,并在完成之前超时)。
所以,我的问题是,从MySQL获取结果集并将其保存为CSV到Google云端存储桶中的最佳方式是什么?
你能写入内存文件吗? –
对不起@JohannesReichard,但我不明白你的问题。我在GAE有点新鲜感。内存文件是我可以写入的东西吗? – James
我从来没有使用GAE,但python不仅支持写入硬盘上的文件,而且还支持类似于存储在内存中的对象的文件:docs.python.org/3/library/io.html#in-memory –