Upload and parse csv file with "universal newline" in python on Google App Engine
Posted
by
greg
on Stack Overflow
See other posts from Stack Overflow
or by greg
Published on 2011-03-17T15:23:40Z
Indexed on
2011/03/17
16:10 UTC
Read the original article
Hit count: 301
Hi,
I'm uploading a csv/tsv file from a form in GAE, and I try to parse the file with python csv module.
Like describe here, uploaded files in GAE are strings.
So I treat my uploaded string a file-like object :
file = self.request.get('catalog')
catalog = csv.reader(StringIO.StringIO(file),dialect=csv.excel_tab)
But new lines in my files are not necessarily '\n' (thanks to excel..), and it generated an error :
Error: new-line character seen in unquoted field - do you need to open the file in universal-newline mode?
Does anyone know how to use StringIO.StringIO to treat strings like files open in universal-newline?
© Stack Overflow or respective owner