python 2.3, cvs module specific question

Skip Montanaro skip at pobox.com
Wed Sep 3 23:06:47 CEST 2003


    Bernard> But this is rejected:

    Bernard>      inf = file('data.csv')
    Bernard>      headers = inf.readline().split(';')
    Bernard>      rd = csv.DictReader( inf, headers, delimiter=';' )
    Bernard>      for row in rd:
    Bernard>          # ...

This is a known problem.  For the time being, define a new dialect class and
pass it in.  If you know what the delimiter is, it's easier to define a
class than call the sniffer.

    class semi(csv.excel):
        delimiter = ';'

    inf = file('data.csv')
    headers = inf.readline().split(';')
    rd = csv.DictReader(f, headers, dialect=semi)
    for row in rd:
        ...

    Bernard> If DialectReader does indeed not accept the optional "fmtparam"
    Bernard> then at least the documentation needs fixing. But then again I
    Bernard> may just be misreading it....

No, it's just a bug in my implementation.

Skip





More information about the Python-list mailing list