parse_qs ... why dictionarykey : list ?

Brian Donovan lists at lophty.com
Wed Jul 31 14:58:06 EDT 2002


> (1.) Why does cgi's parse_qs return each of the param:value pairs in a
> querystring as a dictionary key and a list?
> 
> (2.) How does one format a query string so that lists can actually be
> passed to a Python script via querystring so that parse_qs will "see"
> them? [I've futzed around a bit but haven't stumbled on how it's done.]

I'll reply to my own posting since someone contacted me via email with 
the answer and it may benefit someone else searching the archives some day :

> It's perfectly legal to have more than one input item on an HTML form
> with the same name.  parse_qs returns its results as a list so that if
> there was more than one item with the same name in a querystring you can
> access each value.
> 
> For example, try:
> 
> foo.py?color=Red&color=Blue&color=Green

Thanks to Abe fettig (http://www.fettig.net) for the answer. :D

- brian


-- 
--------------------------------------------------------------------
Brian Donovan, web programmer / researcher
Lophty <http://www.lophty.com> [projects, snippets]
Monokrom <http://www.monokromatik.com> [commentary, writing]
--------------------------------------------------------------------
Namebrand, Corp <http://www.namebrandcorp.net>
--------------------------------------------------------------------




More information about the Python-list mailing list