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

John Machin sjmachin at lexicon.net
Sun Feb 16 12:11:46 CET 2003


On Sun, 16 Feb 2003 05:14:04 +1100, John Machin <sjmachin at lexicon.net> 
wrote:

> (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.

I was wrong; I guessed that _csv.c used PyArg_PTAK, but it doesn't -- it 
rams the Dialect (Python level) instance's attributes plus the csv.reader 
keyword arguments into a DialectType (C level) instance, the setattr being 
eventually done either by PyMember_SetOne, or in _csv.c itself -- in both 
cases, a type mismatch means a call to PyErr_BadArgument() which issues the 
obscure message "bad argument type for built-in operation".

PyArg_PTAK gives a more meaningful message if the required type is a single 
char, for example "argument 2 must be char, not int". However where the 
required type is int, you get "an integer is required" ... looks like a 
patch wouldn't go astray.

Cheers,
John




More information about the Csv mailing list