[Csv] weird default dialects

Skip Montanaro skip at pobox.com
Mon Feb 3 03:13:09 CET 2003


I know the behavior is reasonable, but this code

    class Dialect:
        delimiter = ','
        quotechar = '"'
        escapechar = None
        doublequote = True
        skipinitialspace = False
        lineterminator = '\r\n'
        quoting = QUOTE_MINIMAL

    class excel(Dialect):
        pass

looks really weird to me.  I'd prefer it if the Dialect class simply defined
the various parameters, but gave them invalid values like None or
NotImplemented and then have the excel class fill it its values:

    class Dialect:
        delimiter = None
        quotechar = None
        escapechar = None
        doublequote = None
        skipinitialspace = None
        lineterminator = None
        quoting = None

    class excel(Dialect):
        delimiter = ','
        quotechar = '"'
        escapechar = None
        doublequote = True
        skipinitialspace = False
        lineterminator = '\r\n'
        quoting = QUOTE_MINIMAL

I know that's a bit more verbose, but people probably shouldn't be able to
use Dialect directly, and if they subclass incompletely from Dialect, I
think they should get exceptions.  If what they want is "just like Excel
except ...", they shouldn't be able to get away with subclassing Dialect.
They should have to subclass excel.

I suggested NotImplemented as a possible default value because None *is* a
valid value for at least one of the parameters.

Make sense?

Skip


More information about the Csv mailing list