* separated values

Skip Montanaro skip at pobox.com
Tue Jan 15 23:18:08 CET 2002


    Cliff> I've heard (I haven't looked for myself) that Dave's doesn't
    Cliff> support embedded newlines which is a big killer for many CSV
    Cliff> files...

I think it does the right thing in this regard.  Given this csv file:

    "abc
    def",5,qwerty

running a slightly modified version of the test script that comes with the
package:

    #!/usr/bin/python
    import sys
    import string
    import csv

    p = csv.parser()
    f = open(sys.argv[1])
    while 1:
        l = f.readline()
        if not l:
            break
        r = p.parse(l)
        if r is not None:
            print r

produces this output:

    ['abc\ndef', '5', 'qwerty']

Skip




More information about the Python-list mailing list