Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #20206
| From | Paul Rubin <no.email@nospam.invalid> |
|---|---|
| Newsgroups | comp.lang.python |
| Subject | Re: Postpone evaluation of argument |
| References | <mailman.5686.1328914914.27778.python-list@python.org> |
| Date | 2012-02-10 15:57 -0800 |
| Message-ID | <7xsjii2qd7.fsf@ruckus.brouhaha.com> (permalink) |
| Organization | Nightsong/Fort GNOX |
Righard van Roy <pluijzer@gmail.com> 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
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