[Python-ideas] except expression

Chris Angelico rosuav at gmail.com
Wed Feb 19 02:20:03 CET 2014


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!

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"?)

ChrisA


More information about the Python-ideas mailing list