Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #20220
| From | 88888 Dihedral <dihedral88888@googlemail.com> |
|---|---|
| Newsgroups | comp.lang.python |
| Subject | Re: Postpone evaluation of argument |
| Date | 2012-02-11 03:16 -0800 |
| Organization | http://groups.google.com |
| Message-ID | <412049.429.1328958999552.JavaMail.geo-discussion-forums@pbctz8> (permalink) |
| References | <mailman.5686.1328914914.27778.python-list@python.org> <7xsjii2qd7.fsf@ruckus.brouhaha.com> |
在 2012年2月11日星期六UTC+8上午7时57分56秒,Paul Rubin写道: > Righard van Roy > writes: > > 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: > raise(ValueError) > return x > > def maybe(func): > try: > yield func() > except: > return > 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
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Postpone evaluation of argument Righard van Roy <pluijzer@gmail.com> - 2012-02-11 00:01 +0100
Re: Postpone evaluation of argument Paul Rubin <no.email@nospam.invalid> - 2012-02-10 15:57 -0800
Re: Postpone evaluation of argument 88888 Dihedral <dihedral88888@googlemail.com> - 2012-02-11 03:16 -0800
Re: Postpone evaluation of argument Jussi Piitulainen <jpiitula@ling.helsinki.fi> - 2012-02-11 10:54 +0200
csiph-web