[Csv] This surprised me

Andrew McNamara andrewm at object-craft.com.au
Sat Feb 8 14:08:18 CET 2003


>This code surprised me:
>
>    >>> class foo: pass
[...]
>    >>> rdr = csv.reader(StringIO.StringIO("1,2,3\r\n"), dialect=foo)
>    Traceback (most recent call last):
>      File "<stdin>", line 1, in ?
>      File "/usr/local/lib/python2.3/site-packages/csv.py", line 27, in __init__
>        raise Error, "Dialect did not validate: %s" % ", ".join(errors)
>    _csv.Error: Dialect did not validate: delimiter not set, quotechar not set, lineterminator not set, doublequote setting must be True or False, skipinitialspace setting must be True or False
>
>Why didn't it complain anywhere that 'foo' was worthless as a dialect until
>the last statement?

Surely there's more to your example than you quoted in this e-mail? The
exception you mention came from the python code, not the C module
(specifically the Dialect class), but I can't see where it referenced
in the quoted code?

The C code will instanciate (and thus call Dialect's _validate) when
register_dialect is called, or when the class is passed to reader
or writer.

-- 
Andrew McNamara, Senior Developer, Object Craft
http://www.object-craft.com.au/


More information about the Csv mailing list