DSVWizard.py

Andrew McNamara andrewm at object-craft.com.au
Tue Jan 28 00:25:00 CET 2003


>> >     DSV: ['Test 1', 'Fred said "hey!", and left the room', '']
>> >     csv: ['Test 1', ' "Fred said ""hey!""', ' and left the room"', ' ""']
>> 
>> IMO, Dave's is incorrect in this one (unless he has specific reasons
>> otherwise).
>
>Andrew (who has been included on th Cc) has tested the behaviour of
>Excel (such as it is) and we do the same thing as Excel.  As to
>whether Excel is doing the right thing, that is a different question
>entirely.
[...]
>> The original line (from the csv file) is:
>> 
>> Test 1, "Fred said ""hey!"", and left the room", ""

Excel (at least, Excel 97) only gives the quote character a special
meaning when it appears directly after the field separator. In this
example, you have a space between the comma and the quote - removing
the space, CSV gives you:

    ['Test 1', 'Fred said "hey!", and left the room', '']

Older versions of CSV, in fact, behaved as DSV does (since that makes more
sense), but in the name of Excel compatibility...

>> The "" at the end is an empty, quoted field.  Maybe someone should
>> run this through Excel to see what it claims (I'd be willing to
>> accept Dave's interpretation if Excel does it this way, although I'd
>> still feel it was incorrect).  I handled this case specifically at a
>> user's request.
>
>Andrew, can you run that exact line through Excel?

Excel and CSV are behaving the same way on this line. As I mention above,
the space after the field separator is the problem.

I probably should add a "gobble leading space option" (sigh).

>> > All the three lines have white space immediately following
>> > separating commas.  DSV appears to skip over this white space,
>> > while csv treats it as part of the field contents.
>
>I am fairly sure that is what Excel does.

Indeed.

-- 
Andrew McNamara, Senior Developer, Object Craft
http://www.object-craft.com.au/



More information about the Csv mailing list