[Python-ideas] except expression

Chris Angelico rosuav at gmail.com
Thu Feb 20 02:25:53 CET 2014


On Thu, Feb 20, 2014 at 12:09 PM, Nick Coghlan <ncoghlan at gmail.com> wrote:
> 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).

Thank you, yes. I'll add that message and move the whole idea to the
rejected section.

ChrisA


More information about the Python-ideas mailing list