[Python-ideas] except expression

Nick Coghlan ncoghlan at gmail.com
Thu Feb 20 02:09:59 CET 2014


On 20 February 2014 10:15, Ethan Furman <ethan at stoneleaf.us> wrote:
> try:
>    os.unlink(some_file)
> except OSError:
>    pass

Note that Python 3.4+ (and previous versions once I get around to
doing a new contextlib2 release) allows the statement case to be
written as the one-liner:

    with suppress(OSError): os.unlink(some_file)

I don't think this PEP needs to worry about that case, but Chris may
want to explicitly reference contextlib.suppress as being preferred to
"os.unlink(some_file) except OSError -> None" (or 0 or ... or whatever
other dummy placeholder someone decided to use).

Cheers,
Nick.

-- 
Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia


More information about the Python-ideas mailing list