[mod_python] Beginner question re: getting form data and key errors when var not defined

Damjan gdamjan at mail.net.mk
Mon Oct 27 14:14:04 EST 2003


> This is a really a Python language question, not a mod_python question 
> per se.
> 
> You have several options, including:
> 
> if req.form.has_key('author'):
>   author = req.form['author']
> else:
>   author = None
> 
> Or:
> 
> try:
>   author = req.form['author']
> except KeyError:
>   author = None

or
    req.form.get('author', None)

this if req.form is a standard Python dictionary



-- 
Damjan Georgievski
jabberID: damjan at bagra.net.mk


More information about the Mod_python mailing list