Re: Postpone evaluation of argument

2012-02-11 Thread 88888 Dihedral
在 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 itertool

Re: Postpone evaluation of argument

2012-02-11 Thread Jussi Piitulainen
Righard van Roy writes: > Hello, > > I want to add an item to a list, except if the evaluation of that item > results in an exception. > I could do that like this: > > def r(x): > if x > 3: > raise(ValueError) > > try: > list.append(r(1)) > except: > pass > try: > list.a

Re: Postpone evaluation of argument

2012-02-10 Thread 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: rais

Re: Postpone evaluation of argument

2012-02-10 Thread Chris Rebert
On Fri, Feb 10, 2012 at 3:01 PM, Righard van Roy wrote: > Hello, > > I want to add an item to a list, except if the evaluation of that item > results in an exception. > I could do that like this: > > def r(x): >    if x > 3: >        raise(ValueError) > > try: >    list.append(r(1)) > except: >  

Postpone evaluation of argument

2012-02-10 Thread Righard van Roy
Hello, I want to add an item to a list, except if the evaluation of that item results in an exception. I could do that like this: def r(x): if x > 3: raise(ValueError) try: list.append(r(1)) except: pass try: list.append(r(5)) except: pass This looks rather clumbsy t