[Csv] Coding dialects

Skip Montanaro skip at pobox.com
Wed Jan 29 17:11:34 CET 2003


(Changing the subject to suit to topic a bit better...)

    Cliff> So are we leaning towards dialects being done as simple classes?
    Cliff> Will 'excel-tsv' simply be defined as

    Cliff> class excel_tsv(excel_2000):
    Cliff>     delimiter = '\t'

    Cliff> with a dictionary for lookup:

    Cliff> settings = { 'excel-tsv': excel_tsv,
    Cliff>              'excel-2000': excel_2000, }

    Cliff> ? 

I was thinking of dialects as dicts.  You'd have

    excel_dialect = { "quotechar": '"',
                      "delimiter": ',',
                      "linetermintor": '\r\n',
                      ...
                    }

with a corresponding mapping as you suggested:

    settings = { 'excel': excel_dialect,
                 'excel-tsv: excel_tabs_dialect, }

then in the factory functions do something like:

    def reader(fileobj, dialect="excel", **kwds):
        kwargs = copy.copy(settings[dialect])
        kwargs.update(kwds)
        # possible sanity check on kwargs here ...
        return _csv.reader(fileobj, **kwargs)

Perhaps we could distribute a dialects.csv file ;-) with the module which
defines the supported dialects.  That file would be loaded upon initial
import to define the various dialect dicts.

Skip

_______________________________________________
Csv mailing list
Csv at mail.mojam.com
http://manatee.mojam.com/mailman/listinfo/csv



More information about the Csv mailing list