On Thursday, April 15, 2010 11:23:15 selecta wrote:
> for request.args I can do
> 
> request.args(0)
> 
> and will return None if there is no such element, much nicer than
> 
> request.args[0] if len(request.args)>0 else None
> 
> I always wondered why this does not work for request.vars I have the
> following all over my code
> 
> q = request.vars['q'] if request.vars.has_key('q') else None
> 
> did I miss something?

Hi.

You can do:

q = request.vars.get('q', None)

You can put anything instead of None. It's like a default value.

regards
mmlado

Reply via email to