[CentralOH] csv.DictReader file mode
Neil Ludban
nludban at columbus.rr.com
Tue Oct 23 03:24:04 CEST 2012
On Mon, 22 Oct 2012 14:55:35 -0400
jep200404 at columbus.rr.com wrote:
> On Sun, 21 Oct 2012 22:46:15 -0400, jep200404 at columbus.rr.com wrote:
>
> > csv.DictReader(z.open(f, 'rU'))
>
> Going back and RTFMing[1], I see something that makes me wonder
> about the wisdom of using universal newline support.
>
> If csvfile is a file object, it must be opened with the ?b?
> flag on platforms where that makes a difference.
I tried tracking down CSV standards a couple months ago while writing
a reader and writer in C++ (borrowing heavily from Python's csv.Dialect).
The best reference I found was
http://tools.ietf.org/html/rfc4180
which says CRLF must be used for MIME (same as for any other text
format, http://tools.ietf.org/html/rfc2046).
After thinking about it a bit more, I believe my conclusion was
that it was reasonable for the application I was working on to
assume any end user bright enough to get a non-Excel compatible
CSV file onto a Windows machine was also capable of making any
translations to make it compatible. YMMV :)
If I were doing the same thing in Python, I'd try opening the
file with universal endlines, let csv.Sniffer figure out the
details of a Dialect, and then force dialect.lineterminator = '\n'.
> [1] http://www.python.org/doc//current/library/csv.html#csv.reader
>
> _______________________________________________
> CentralOH mailing list
> CentralOH at python.org
> http://mail.python.org/mailman/listinfo/centraloh
More information about the CentralOH
mailing list