Unexpected behaviour of csv module
Andrew McLean
andrew-news at andros.org.uk
Mon Sep 25 03:54:42 EDT 2006
John Machin wrote:
> A better workaround IMHO is to strip each *field* after it is received
> from the csv reader. In fact, it is very rare that leading or trailing
> space in CSV fields is of any significance at all. Multiple spaces
> ditto. Just do this all the time:
>
> row = [' '.join(x.split()) for x in row]
The problem with removing the spaces after they are received from the
csv reader is if you want to use DictReader. I like to use DictReader,
without passing it the field list. The module then reads the field list
from the first line, and in this situation you don't get an opportunity
to strip the spaces from that.
More information about the Python-list
mailing list