nothing shorter than this
def s(*args, **kwargs):
rtn = {}
for a in args:
rtn[a] = kwargs['l'].get(a)
return rtn
def test():
images = 'a'
stories = 'b'
l = locals()
return s('images','stories', l=l)
PS: there's no way to retrieve name of variables from statements like
"return images, values", because they are evaluated. Namedtuple are the
most "minimal" structures allowing that, but code to create a new
namedtuple is several characters longer (and you're basically asking for
less characters ^_^)
On Wednesday, October 17, 2012 1:34:26 AM UTC+2, Marek Mollin wrote:
>
> Hello,
> I was wondering if web2py controllers could adapt returning just variables.
> Either as single variable or python implicit tuple.
>
> def index():
> return images,stories
>
> They would implicitly be getting the same dict keys.
> But I often find it redundant to do it (return dict(images=images,
> stories=stories)) yet I do not want return all the local variables . I know
> that if I return a variable it returns that plain text but I wondering if
> anybody is using it this way?
>
>
>
--