DSVWizard.py

Dave Cole djc at object-craft.com.au
Mon Jan 27 06:13:34 CET 2003


>     Cliff> I think even Excel has the option to import files using "/'/none
>     Cliff> for text qualifiers.  This was the only shortcoming I saw in csv
>     Cliff> (only " is used for quoting).
> 
> Actually, csv's parser objects have a writable quote_char attribute:
> 
>     >>> import csv
>     >>> p = csv.parser()
>     >>> p.quote_char
>     '"'
>     >>> p.quote_char = "'"
>     >>> p.quote_char
>     "'"

For all sorts of fun and games you can even turn off quoting.

>>> import csv
>>> p = csv.parser()
>>> p.join(['1','2,3','4'])
'1,"2,3",4'
>>> p.escape_char = '\\'
>>> p.join(['1','2,3','4'])
'1,"2,3",4'
>>> p.quote_char = None
>>> p.join(['1','2,3','4'])
'1,2\\,3,4'

- Dave

-- 
http://www.object-craft.com.au




More information about the Csv mailing list