在Google App Engine上在线生成CSV文件 [英] generating a CSV file online on Google App Engine
问题描述
我使用的是Google App Engine(python),我希望我的使用者能够下载使用资料储存库中的部分资料所产生的CSV档案(但我不希望他们下载整个资料,
I am using Google App Engine (python), I want my users to be able to download a CSV file generated using some data from the datastore (but I don't want them to download the whole thing, as I re-order the columns and stuff).
我必须使用csv模块,因为可以有包含逗号的单元格。但是问题是,如果我这样做,我将需要写一个文件,这是不允许在Google App Engine
I have to use the csv module, because there can be cells containing commas. But the problem that if I do that I will need to write a file, which is not allowed on Google App Engine
我现在有这样的: p>
What I currently have is something like this:
tmp = open("tmp.csv", 'w')
writer = csv.writer(tmp)
writer.writerow(["foo", "foo,bar", "bar"])
所以我想我想要做的是使用逗号处理单元格或使用csv模块没有写入文件,因为这是不可能与GAE ..
So I guess what I would want to do is either to handle cells with commas.. or to use the csv module without writing a file as this is not possible with GAE..
推荐答案
我发现了一种在GAE上使用CSV模块的方法!这是:
I found a way to use the CSV module on GAE! Here it is:
self.response.headers['Content-Type'] = 'application/csv'
writer = csv.writer(self.response.out)
writer.writerow(["foo", "foo,bar", "bar"])
这样你就不需要写任何文件了。
This way you don't need to write any files
这篇关于在Google App Engine上在线生成CSV文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!