[Python-ideas] except expression
Chris Angelico
rosuav at gmail.com
Thu Feb 20 02:00:09 CET 2014
On Thu, Feb 20, 2014 at 11:15 AM, Ethan Furman <ethan at stoneleaf.us> wrote:
> which would be converted to (using Nick's notation):
>
> result = 1/x except ZeroDivisionError -> NaN
>
> result = some_func(value1, value2) except SomeError -> 42
These two I strongly support (colon or arrow, either way).
> os.unlink(some_file) except OSError -> None
This one, not so much. You're using os.unlink(some_file) as a
statement, ignoring its return value. Changing its return value to
None in the case of an exception isn't exactly what you're trying to
do. Yes, it does make for a one-liner, where the full form takes two:
try: os.unlink(some_file)
except OSError: pass
but I'm not sure that it's the right way to do things.
ChrisA
More information about the Python-ideas
mailing list