W
wheres pythonmonks
Hi!
I have on a few occasions now wanted to have inline-exception
handling, like the inline if/else operator.
For example,
The following might raise ZeroDivisionError:
f = n / d
So, I can look before I leap (which is okay):
f = float("nan") if d == 0 else n/d;
But, what I'd like to be able to write is:
f = n / d except float("nan");
Which I find much more appealing than:
try:
f = n / d
except:
f = float("nan")
(Obviously, I am thinking about more complicated functions than "n/d"
-- but this works as an example.)
Thoughts?
W
I have on a few occasions now wanted to have inline-exception
handling, like the inline if/else operator.
For example,
The following might raise ZeroDivisionError:
f = n / d
So, I can look before I leap (which is okay):
f = float("nan") if d == 0 else n/d;
But, what I'd like to be able to write is:
f = n / d except float("nan");
Which I find much more appealing than:
try:
f = n / d
except:
f = float("nan")
(Obviously, I am thinking about more complicated functions than "n/d"
-- but this works as an example.)
Thoughts?
W