Jeff McAninch wrote:
> I very often want something like a try-except conditional expression similar> to the if-else conditional.
I think it may be done currently with the help of next function:
def guard(func, *args):
except Exception, e:
for exc_type, exc_func in args:
if isinstance(e, exc_type):
a, b, c = 10, 20, 0
result = a + b/c # raise ZeroDivisionError
result = a + guard(lambda: b/c, (TypeError, lambda: 10),
(ZeroDivisionError, lambda: b/2))
May be not very concise, but it works...
Alexander mailto:alexander.kozlovsky at gmail.com