Actually. What if we just reused 'try'?
On Thu, Feb 13, 2014 at 3:25 AM, spir <denis.spir@gmail.com> wrote:
Of course, it could be done as a function call:
def catch(callme, catchme, returnme):
try:
return callme()
except catchme:
return returnme
phone = catch(lambda: addressbook[name], KeyError, "Unknown")
but that's *really* clunky.I don't really find this function all the clunky. However, it also does not solve the case of an expensive 'except' clause that Nick pointed out as desirable to avoid evaluating (or, for that matter, an except clause with side effects).E.g.phone = catch(lambda: addressbook[name], KeyError, lookup_from_internet(name))
--
Keeping medicines from the bloodstreams of the sick; food
from the bellies of the hungry; books from the hands of the
uneducated; technology from the underdeveloped; and putting
advocates of freedom in prisons. Intellectual property is_______________________________________________
to the 21st century what the slave trade was to the 16th.
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/