[PEP305] Python 2.3: a small change request in CSV module

Bernard Delmée bdelmee at advalvas.REMOVEME.be
Fri May 16 16:22:11 EDT 2003


> I have my own special interests (mostly reading and writing
> multi-megabyte CSV files), but I don't think I've ever not known what
> the delimiter was. Still, that may just be because I live in the
> bully country of which Texas is a part. :-(

Erh, did that mean "no"? Ah, those young Americans!
"Bully for you, chilly for me".

A generator will have to do, then:

import csv

def sniffer_reader( fname ):
    infile = file( fname )
    sample = infile.read( 8192 )
    dialect = csv.Sniffer().sniff( sample )
    infile.seek( 0 )
    for row in csv.reader( infile, dialect ):
        yield row

for fields in sniffer_reader( 'data.csv' ):
    # do something with fields







More information about the Python-list mailing list