questions concerning cgi.FieldStorage(keep_blank_values=1)

Michele Simionato michele.simionato at gmail.com
Mon Feb 21 00:51:35 EST 2005


Jonas:
> in this application, i need keys to be delivered with the url, some
with
> and some without value (for example 'script.py?key1&key2=foo'.

You are missing an "=" sign after key1. Confront with this example:

from cgi import parse_qsl

QS = "x=1&y=2&x=3&z=&y=4"
print parse_qsl(QS)
print parse_qsl(QS, keep_blank_values=True)

which gives

[('x', '1'), ('y', '2'), ('x', '3'), ('y', '4')]
[('x', '1'), ('y', '2'), ('x', '3'), ('z', ''), ('y', '4')]

Here the blank value "z=" is converted into "z=''".


                   Michele Simionato




More information about the Python-list mailing list