使用数据存储中的属性写入文件
我想要一个以逗号分隔的列表,其中包含我的应用程序存储的所有电子邮件地址。它对于常规请求来说太大了,并且将其写入 blobstore 也是一个太大的请求:
class CSVHandler(webapp2.RequestHandler):
def get(self):
entities = Entity.all().fetch(10000)
s = ''
for entity in entities:
s= s+","+str(entity.email)
file_name = files.blobstore.create(mime_type='application/octet-stream')
with files.open(file_name, 'a') as f:
f.write(s)
files.finalize(file_name)
blob_key = files.blobstore.get_blob_key(file_name)
我可以将其作为任务、队列、后端或其他东西来实现吗?
预先感谢您的任何建议
I want a comma-separated list of all the email addresses my application stores. It's too large for a regular request and writing it to the blobstore is also a too large request:
class CSVHandler(webapp2.RequestHandler):
def get(self):
entities = Entity.all().fetch(10000)
s = ''
for entity in entities:
s= s+","+str(entity.email)
file_name = files.blobstore.create(mime_type='application/octet-stream')
with files.open(file_name, 'a') as f:
f.write(s)
files.finalize(file_name)
blob_key = files.blobstore.get_blob_key(file_name)
Can I do it as a task, a queue, a backend or something else instead?
Thank you in advance for any suggestion
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不要尝试在单个写入操作中保存整个文件,而是将其分块写入 blobstore。使用
csv
模块将使这变得更容易,允许您逐步编写它。Instead of trying to save the entire file in a single write operation, write it to the blobstore in chunks. Using the
csv
module will make this easier, allowing you to write it progressively.您可能应该使用内置的批量加载器工具,该工具可以通过远程 API 下载所有对象并将所选字段保存为 CSV 格式。
You should probably use the built-in bulkloader tool, which can download all objects via the remote API and save selected fields into CSV format.