[Python-ideas] except expression

Jan Kaliszewski zuo at chopin.edu.pl
Wed Feb 19 02:48:24 CET 2014


19.02.2014 02:20, Chris Angelico wrote:

> On Wed, Feb 19, 2014 at 12:16 PM, Jan Kaliszewski <zuo at chopin.edu.pl> 
> wrote:
>>> Annotated examples:
>>> https://github.com/Rosuav/ExceptExpr/blob/master/examples.py
>>
>>
>> Excellent! :)
>>
>> One more minor motivating case:
>>
>>     q = queue.Queue(maxsize=10)
>>     ...
>>     item = q.get_nowait() except Full: default
>>
>> (in case of a list you could check its length to avoid catching
>> exception; but Queue's usage cases are typically multi-threading
>> -related so the "check and then get" way is not an option then)
>
> The examples I'm quoting there are from actual real-world code - in
> this case, *.py in the cpython source tree. Do you have some
> real-world code that does the above with a try/except, and which is
> available for viewing and analysis? If so, I'd be happy to add that 
> to
> the examples!

Then I was writing that it seemed to me that I encountered such cases
in some code I saw not so long ago.  But I don't remember the details
and indeed am not sure.  So -- nevermind. :)

> Otherwise, if this is just a contrived/theoretical example, I can
> still add it someplace, but we already have a good few of those.
>
> (BTW, should that be "except Empty"?)

Yes, it should.

Sorry, it's 2:46 *a.m.* here...  You just caught my TooLateNightError 
:)

Cheers.
*j



More information about the Python-ideas mailing list