Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Decision (if, else) routine is not working as intended with CGImodule

Reply
Thread Tools

Decision (if, else) routine is not working as intended with CGImodule

 
 
epsilon
Guest
Posts: n/a
 
      01-29-2008
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.

Thank you,
Christopher

++++++++++

#!/usr/bin/python

import cgi

print "Content-type: text/plain\n"
tag_form = cgi.FieldStorage(keep_blank_values=True)

#if not tag_form.has_key("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"]
 
Reply With Quote
 
 
 
 
Gabriel Genellina
Guest
Posts: n/a
 
      01-29-2008
En Tue, 29 Jan 2008 18:23:41 -0200, epsilon <(E-Mail Removed)> escribi�:

> 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.
>
> tag_form = cgi.FieldStorage(keep_blank_values=True)
>
> #if not tag_form.has_key("fse00"):
> if tag_form["fse00"] == "":


tag_form["fse00"] is a FieldStorage instance, not a string. To get its
value, use:

if tag_form["fse00"].value == ""
if tag_form.getvalue("fse00")==""
if tag_form.getfirst("fse00")==""

See http://docs.python.org/lib/module-cgi.html

--
Gabriel Genellina

 
Reply With Quote
 
 
 
 
bruno.desthuilliers@gmail.com
Guest
Posts: n/a
 
      01-29-2008
On 29 jan, 21:23, epsilon <(E-Mail Removed)> 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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Globalization not working as intended when using da-DK Basildk ASP .Net 8 08-31-2007 08:26 AM
LoginView - I'm probably trying to use it in a way that's not intended... Homer J. Simpson ASP .Net 0 08-29-2007 07:52 PM
is asynchat broken or just not intended to work like other dispatchers? [PATCH] Martin Maney Python 1 04-11-2007 07:34 PM
Parallel::ForkManager not working as intended on Windows Server 2003 chaitu Perl Misc 2 09-21-2006 06:03 AM
nested includes not working as intended Mike ASP General 4 08-05-2003 02:59 PM



Advertisments