catching exceptions from an except: block

Bruno Desthuilliers bdesth.quelquechose at
Thu Mar 8 00:05:11 CET 2007

Gabriel Genellina a écrit :
> En Wed, 07 Mar 2007 18:48:18 -0300, Arnaud Delobelle  
> <arnodel at> escribió:
>> for f in int, float, complex:
>>     try:
>>         return f(x)
>>     except ValueError:
>>         continue
>> raise CantDoIt
>> But if the three things I want to do are not callable objects but
>> chunks of code this method is awkward because you have to create
>> functions simply in order to be able to loop over them (this is whay I
>> was talking about 'abusing loop constructs').  Besides I am not happy
>> with the other two idioms I can think of.
> Hmmm, functions are cheap 

To define. You pay the price when you call them !-)

(sorry, couldn't resist - I otherwise totally agree with you)

More information about the Python-list mailing list