beginner python cgi question

Jochen Wersdoerfer jochen at helferlein.net
Sat Dec 13 12:06:07 CET 2003


+--[ Brandon Boles ]---[ email at nowhere.foo ]
| ...snip...
| fields=cgi.FieldStorage()
|     if (fields.has_key("name") and fields.has_key("emailaddr")):
|         SenderName=fields["name"].value
|         Address=fields["address"].value
|         City=fields["city"].value
|         State=fields["state"].value
| ...snip...
|
| I think what the problem is that if my form does not have one of the
| fields (except 'name' and 'emailaddr') with data in it, I get this error. 
| What is the best way to fix this?

Getting a default value, if "address" is not set:

Address = fields.get("address", "n/a")

jochen




More information about the Python-list mailing list