[Python-Dev] Proposal: add odict to collections

Phillip J. Eby pje at telecommunity.com
Sun Jun 15 16:29:05 CEST 2008


At 02:19 PM 6/15/2008 +0000, Antoine Pitrou wrote:
> > Ordered dicts, dicts that remember the chronological order of their
> > insertion, don't sound generally useful.
>
>They are generally useful in any case where you want to handle key-value
>pairs while not confusing a human operator by messing up the original order.
>Think e.g. configuration files. A common complaint against ConfigParser is
>that writing a configuration file does not preserve the order of the original
>file, which is harmless for the computer but very annoying for the human
>being who maintains that file.

You don't need an ordered dictionary for that; you need a save 
routine that stream-edits the old file contents.  That way, you don't 
lose comments and spacing either.

As for the other uses for ordered dictionaries, I find it simplest to 
just use a list of key,value pairs, and only transform it to a 
dictionary or dictionary-like structure as needed, using tools like 
the cgi module, the email package, or wsgiref.headers.



More information about the Python-Dev mailing list