在 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
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
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
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:
>
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