Decision (if, else) routine is not working as intended with CGI module
bruno.desthuilliers at gmail.com
bruno.desthuilliers at gmail.com
Tue Jan 29 18:34:23 EST 2008
On 29 jan, 21:23, epsilon <cesm... at gmail.com> wrote:
> All:
>
> I'm running into trouble figuring this one out. It seems that my
> decision routine is not working as intended. Does anyone know why my
> output continues to utilize the "else" portion of the routine.
Probably because the test expression 'tag_form["fse00"] == ""' evals
to false ?
Hint: try printing out tag_form["fse00"] before the test, ie:
(snip)
>
> #!/usr/bin/python
>
> import cgi
>
> print "Content-type: text/plain\n"
> tag_form = cgi.FieldStorage(keep_blank_values=True)
>
print "tag_form[\"fse00\"] is actually: %s" % tag_form["fse00"]
print "tag_form[\"fse00\"] == '' evals to: %s" % (tag_form["fse00"]
== '')
> if tag_form["fse00"] == "":
> fse000 = {"fse00": "0"}
> tag_form.update(fse000)
> print "Printing fse000: ", tag_form["fse00"]
> else:
> print "Printing fse00: ", tag_form["fse00"]
HTH
More information about the Python-list
mailing list