Postpone evaluation of argument
dihedral88888 at googlemail.com
Sat Feb 11 12:16:39 CET 2012
在 2012年2月11日星期六UTC+8上午7时57分56秒，Paul Rubin写道：
> Righard van Roy
> > I want to add an item to a list, except if the evaluation of that item
> > results in an exception.
> This may be overkill and probably slow, but perhaps most in the spirit
> that you're asking.
> from itertools import chain
> def r(x):
> if x > 3:
> return x
> def maybe(func):
> yield func()
I am wondering at which level to yield in a nested decorated function
is more controllable.
It is definitely wrong to yield in manny levels decorated.
> def p(i): return maybe(lambda: r(i))
> your_list = list(chain(p(1), p(5)))
> print your_list
More information about the Python-list