Andrew Dalke's space example (was Re: [Csv] csv)

Dave Cole djc at object-craft.com.au
Sun Feb 16 11:59:21 CET 2003


> There are various problems brought out by Andrew's example; see
> attached file dalke.py
> 
> These are
> (1) very obscure error message "TypeError: bad argument type for
> built-in operation" caused by using quotechar = False instead of
> quotechar = None Also this appears out of the reader() call, not the
> register_dialect() call!!!  *IF* there is a valid use case for
> registration, then the dialect should be validated then, not when
> used.

+1 on that one.  I scratched my head for a while when seeing that
error too.  It wasn't until I read through the C code that the penny
dropped.

> (2) says it needs quotechar != None even when quoting=QUOTE_NONE

+1

> (3) The "quoting" argument is honoured only by writers, not by
> readers -- i.e. in general you can't reliably read back a file that
> you've created and in particular to read Andrew D's files you need
> to set quotechar to some char that you hope is not in the input --
> maybe '\0'.

Aside from the quote of '\0', I am not sure I follow what you mean.
If you set quoting so that it produces ambiguous output that is hardly
the fault of the writer.

> (4) Maybe the whole dialect thing is a bit too baroque and Byzantine
> -- see example 5 in dalke.py. The **dict_of_arguments gadget offers
> the "don't need to type long list of arguments" advantage claimed
> for dialect classes, and you get the same obscure error message if
> you stuff up the type of an argument (see example 6) -- all of this
> without writing all that register/validate/etc code.

How much clearer would things be if the validation of dialects were
pulled up into the Python?  Being able to see the Python code which
raised the exception would be a huge help to the user.

- Dave

-- 
http://www.object-craft.com.au



More information about the Csv mailing list