well, I didn't know about the "or" construction. Now that's elegant ! :-)
Learning Python with web2py is a pleasure. Thank you. On Apr 22, 4:18 pm, mdipierro <mdipie...@cs.depaul.edu> wrote: > you can do > > myvalue=request.vars.get('offset','somedefaultvalue') > > or, which I like better > > myvalue=request.vars.offset or 'somedefaultvalue' > > On 22 Apr, 02:32, desfrenes <desfre...@gmail.com> wrote: > > > ok! Being influenced by other frameworks I was expecting something > > like this: > > > myvalue = request.vars.offset.defaults('some default value') > > > where defaults() would either return the actual value or the default > > value (as seen in ZF: $myvalue = $request->getParam('offset', 'some > > default value');). > > > But I understand the gain is not worth the pain since the python "if" > > statement is explicit and already pretty short. > > > On Apr 21, 10:58 pm, mdipierro <mdipie...@cs.depaul.edu> wrote: > > > > This is elegant. > > > > On 21 Apr, 14:57, desfrenes <desfre...@gmail.com> wrote: > > > > > Hi ! > > > > > I was looking for a way to set default values to request.vars. I use > > > > this: > > > > > if request.vars.offset == None: request.vars.offset = 0 > > > > > But maybe there is a more elegant solution ? --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "web2py Web Framework" group. To post to this group, send email to web2py@googlegroups.com To unsubscribe from this group, send email to web2py+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/web2py?hl=en -~----------~----~----~----~------~----~------~--~---