librelist archives

« back to archive

why use a lambda without a parameter?

why use a lambda without a parameter?

From:
chen ge
Date:
2010-09-29 @ 00:17
g = LocalProxy(lambda: _request_ctx_stack.top.g)


when I write "g.db" before request, it proxy to the top.g. Is this
understanding right?

-- 
regards

chenge

Re: [flask] why use a lambda without a parameter?

From:
Daniel Neuhäuser
Date:
2010-09-29 @ 01:15
> when I write "g.db" before request, it proxy to the top.g. Is this
> understanding right?
Correct. Each time you access g.db the function is called to retrieve
the db attribute of the current top request context from the stack.