[Python-ideas] except expression
Ethan Furman
ethan at stoneleaf.us
Thu Feb 20 01:15:25 CET 2014
The three use-cases I find compelling are:
# long form
try:
result = 1/x
except ZeroDivisionError:
result = NaN # previously defined
try:
os.unlink(some_file)
except OSError:
pass
try:
result = some_func(value1, value2)
except SomeError:
result = 42
which would be converted to (using Nick's notation):
result = 1/x except ZeroDivisionError -> NaN
os.unlink(some_file) except OSError -> None
result = some_func(value1, value2) except SomeError -> 42
Clean, clear, concise.
For the record, I could just as easily live with the colon instead of the arrow.
--
~Ethan~
More information about the Python-ideas
mailing list