You can do: q = request.vars.q or None
On Apr 15, 5:05 am, Mladen Milankovic <[email protected]> wrote: > 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 -- To unsubscribe, reply using "remove me" as the subject.

