Actually. What if we just reused 'try'?<br><br><div> foo = bar() except BazException try 'qux'</div><div><br></div><div>This also leads naturally to chaining multiple possible fallbacks:</div><div><br></div>
<div> foo = bar() except BarException try baz() except BazException try None</div><br><div>On Thu Feb 13 2014 at 10:32:16 AM, David Mertz <<a href="mailto:mertz@gnosis.cx">mertz@gnosis.cx</a>> wrote:</div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div dir="ltr"><div><div>On Thu, Feb 13, 2014 at 3:25 AM, spir <span dir="ltr"><<a href="mailto:denis.spir@gmail.com" target="_blank">denis.spir@gmail.com</a>></span> wrote:<br>
<blockquote style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><blockquote style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Of course, it could be done as a function call:<br>
<br>
def catch(callme, catchme, returnme):<br>
try:<br>
return callme()<br>
except catchme:<br>
return returnme<br>
<br>
phone = catch(lambda: addressbook[name], KeyError, "Unknown")<br>but that's *really* clunky.<br></blockquote></div></blockquote><div><br></div></div></div></div><div dir="ltr"><div><div><div>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).</div>
<div><br></div><div>E.g.</div><div><br></div><div> phone = catch(lambda: addressbook[name], KeyError, lookup_from_internet(name))</div><div><br></div><div><br></div></div></div></div><div dir="ltr"><div><br clear="all">
<div><br></div>-- <br>Keeping medicines from the bloodstreams of the sick; food <br>
from the bellies of the hungry; books from the hands of the <br>uneducated; technology from the underdeveloped; and putting <br>advocates of freedom in prisons. Intellectual property is</div></div><div dir="ltr"><div><br>
to the 21st century what the slave trade was to the 16th.<br>
</div></div>
______________________________<u></u>_________________<br>
Python-ideas mailing list<br>
<a href="mailto:Python-ideas@python.org" target="_blank">Python-ideas@python.org</a><br>
<a href="https://mail.python.org/mailman/listinfo/python-ideas" target="_blank">https://mail.python.org/<u></u>mailman/listinfo/python-ideas</a><br>
Code of Conduct: <a href="http://python.org/psf/codeofconduct/" target="_blank">http://python.org/psf/<u></u>codeofconduct/</a></blockquote>