appengine: parse a csv data in uploaded file

2019-07-17 03:17发布

Are there any modules or packages which help parsing csv content from a uploaded csv file in appengine. tried using the csv package in python. but it could parse only files in file system but could not data.. http://docs.python.org/library/csv.html

2条回答
太酷不给撩
2楼-- · 2019-07-17 03:59

but it could parse only files in file system but could not data

No, csv.reader accepts any object that supports line-by-line iteration. Assuming cgi.FieldStorage supports it, and assuming you've posted a file named "file", you should be able to do this:

import csv
for row in csv.reader(self.request.POST['file']):
  # process row
查看更多
放我归山
3楼-- · 2019-07-17 04:06

There is a blobstore input format for the App Engine Mapper: http://code.google.com/p/appengine-mapreduce/

It will read each line from the CSV and send it to your mapper for reading/import. Be careful though because it breaks if there are escaped new lines in the CSV.

Here is an example with the Java implementation: http://ikaisays.com/2010/08/11/using-the-app-engine-mapper-for-bulk-data-import/

查看更多
登录 后发表回答