csv: No fields, or one field?

Neil Cerutti neilc at norwich.edu
Wed Apr 25 14:52:20 EDT 2012


On 2012-04-25, Kiuhnm <kiuhnm03.4t.yahoo.it> wrote:
> On 4/25/2012 20:05, Neil Cerutti wrote:
>> Is there an explanation or previous dicussion somewhere for the
>> following behavior? I haven't yet trolled the csv mailing list
>> archive, though that would probably be a good place to check.
>>
>> Python 3.2 (r32:88445, Feb 20 2011, 21:29:02) [MSC v.1500 32 bit
>> (Intel)] on win 32
>> Type "help", "copyright", "credits" or "license" for more information.
>>>>> import csv
>>>>> next(csv.reader(['""\r\n']))
>> ['']
>>>>> next(csv.reader(['\r\n']))
>> []
>
> This should be documented (I trust you when you say it isn't),
> but it makes a lot of sense:
>
> >>> next(csv.reader(['']))
> []
> >>> next(csv.reader(['""']))
> ['']
> >>> next(csv.reader([',']))
> ['', '']
> >>> next(csv.reader([',,']))
> ['', '', '']

It is definitely consistent and usable, once the quoting truck is
learned.

-- 
Neil Cerutti



More information about the Python-list mailing list