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

Skip Montanaro skip at pobox.com
Fri May 16 15:08:16 EDT 2003


    >> I'll leave Dave and Andrew to comment on the possibility of admitting
    >> a multiple-character delimiter string, as that will affect their C
    >> code.

    Bernard> Are they monitoring this ng as well, or should I repost
    Bernard> elsewhere?  Notice I am not asking for a multichar delimiter
    Bernard> but for multiple alternate single-char separators.

As I mentioned in my original note, the best place for this discussion is
csv at mail.mojam.com.  I'm sure Dave and Andrew are there.  I don't know how
regularly they monitor c.l.py.

    Bernard> for fields in csv.reader( infile, dialect='sniff' ):
    Bernard>     # do something with fields

    >> Do you mean to imply that the csv.reader object should call the
    >> sniffer implicitly and use the values it returns?  That's an
    >> interesting idea but the sniffer isn't guaranteed to always guess
    >> right.

    Bernard> Yes that's exactly my suggestion. 

I'm not sure we have that much confidence in the sniffer at this point.  

    Bernard> Also, if this was supported directly in reader(), the file-like
    Bernard> argument would not necessarily have to be seekable, it could
    Bernard> conceivably just use the first read data chunk for the
    Bernard> guess-work as well as for further parsing of the first rows.

Not necessarily.  It depends on how the file is accessed.  I believe it's
treated as an iterator, it which case you wind up having to read several
records, pass them off to the sniffer, set your dialect, reprocess the lines
you've already read, then process the remaining unread lines in the file.
This would be more tedious from C than from Python.

    Bernard> I hope this could be deemed a common enough usage to grant
    Bernard> inclusion in the standard module.

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. :-(

Skip






More information about the Python-list mailing list