Help a newbie revise my program

Paul McGuire ptmcg at austin.rr._bogus_.com
Mon Apr 26 01:11:05 EDT 2004


"Sean Berry" <sean_berry at cox.net> wrote in message
news:5SZic.98241$U83.18636 at fed1read03...
> My program is used by an applet to look up items in a mysql database.
> It is a "smart program".  By that I mean it returns different results
based
> on
> the arguments from the URL.  Like,
> www.domain.com/cgi-bin/getModels?shaped=5&sized=7
>
> It works well enough.  However, I would like to find out better ways to do
> some of the things I am doing,
> such as getting the variable values from the URL.
>

I think you'll find some helpful stuff in the cgi module, especially
parse_qs(queryString), which in your example will return a dictionary as
follows:

>>> import cgi
>>> print cgi.parse_qs("shaped=5&sized=7")
{'sized': ['7'], 'shaped': ['5']}
>>>

I can't explain why the dictionary values are lists, though - I would have
expected scalar strings.

-- Paul





More information about the Python-list mailing list