[Csv] CSV interface question

Andrew McNamara andrewm at object-craft.com.au
Wed Jan 29 07:05:01 CET 2003


In the proposed PEP, we have separate instances for reading and writing.
In the Object Craft csv module, a single instance is shared by the parse
and join methods - the only virtue of this is config is shared (so the
same options are used to write the file as were used to read the file).

Maybe we should consider a "container of options" class (of which the
dialects would be subclasses). The sniffing code could then return an
instance of this class (which wouldn't necessarily be a dialect). With
this, you might do things like:

    options = csv.sniffer(open("foobar.csv"))
    for fields in csv.reader(open("foobar.csv"), options)
        ... do stuff

    csvwriter = csv.writer(open("newfoovar.csv", "w"), options)
    try:
        for fields in whatever:
            csvwriter.write(fields)
    finally:
        csvwriter.close()

The idea being you'd then re-write the file with the same sniffed options.

Another idea occurs - looping over an iteratable is going to be common - we
could probably supply a convenience function, say "writelines(iteratable)"?

-- 
Andrew McNamara, Senior Developer, Object Craft
http://www.object-craft.com.au/
_______________________________________________
Csv mailing list
Csv at mail.mojam.com
http://manatee.mojam.com/mailman/listinfo/csv



More information about the Csv mailing list