[Python-ideas] except expression

Ethan Furman ethan at stoneleaf.us
Thu Feb 20 03:29:43 CET 2014


On 02/19/2014 05:25 PM, Chris Angelico wrote:
> 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.

Careful how you word that.  "Rejected" makes it sound like it won't work, not that it will but is not the best way.

--
~Ethan~


More information about the Python-ideas mailing list