Where is the syntax for the dict() constructor ?!

Neil Cerutti horpner at yahoo.com
Thu Jul 5 15:31:33 EDT 2007


On 2007-07-05, Captain Poutine <captainpoutine at gmail.com> wrote:
> "Reader objects (DictReader instances and objects returned by
> the reader() function) have the following public methods:

Lucky for you and me, Peter Otten corrected my mistaken advice.

> next( 	)
>      Return the next row of the reader's iterable object as a list, 
> parsed according to the current dialect."
>
> But that's not enough information for me to use.  Also, the doc
> says basically "csv has dialects," but doesn't even enumerate
> them.  Where is the real documentation?

It's referring to the fact that csv has no standard to adhere to,
so sometimes slightly different ways of quoting and escaping
appear in csv files. Apart from that, through configuring a new
dialect you can use csv to parse many kinds of delimited data
files, not just csv as written by MS apps.

Mostly you can use the default 'excel' dialect and be quite
happy, since Excel is the main reason anybody still cares about
this unecessarily hard to parse (it requires more than one
character of lookahead for no reason except bad design) data
format.

See Library Reference 9.1.2 Dialects and Formatting Paremeters
for an explanation of what can be configured.

> Also, when I do a print of row, it comes out as:
> ['12345', 'ET']
>
> But there are no quotes around the number in the file.  Why is
> Python making it a string?

It's a string to start with, since it comes from a text file.
Besides, a string is an excellent epresentation for a zip code,
since arithmetic upon them is unthinkable.

I shared your frustration with the csv module docs when I first
read them. But happily you can skip them and just read
the easily adapted examples (9.1.5 Examples).

-- 
Neil Cerutti



More information about the Python-list mailing list