Guarding arithmetic
Chris Angelico
rosuav at gmail.com
Thu Aug 23 17:48:20 EDT 2012
On Fri, Aug 24, 2012 at 4:49 AM, Dennis Lee Bieber
<wlfraed at ix.netcom.com> wrote:
> By the time you wrap the equation with a lambda all, named, terms,
> AND supply the named terms after the lambda, you might as well just wrap
> the equation in a plain try/except block.
But closures spare you that hassle.
>>> a=1
>>> b=0
>>> print(safe(lambda: a/b))
42
>>> b=2
>>> print(safe(lambda: a/b))
0.5
(Example done in Python 3 so semantics are a little different)
ChrisA
More information about the Python-list
mailing list