On Sat, Aug 1, 2020 at 1:43 PM Steven D'Aprano <st...@pearwood.info> wrote:
> Some years ago, someone (I think it was Nick Coghlan?) proposed a
> standard solution for this issue, a context manager + decorator function
> that guarded against a specific exception. Nothing much came of it, but
> I did experiment with the idea, and got something which you could use
> like this:
>
>     with exception_guard(StopIteration):
>         first = next(iter(mydict.items()))

My understanding of this is that 'first' is unassigned if StopIteration happens.

> or like this:
>
>     safenext = exception_guard(StopIteration)(next)
>     first = safenext(iter(mydict.items()))
>

My understanding of this is that I am confused. What does safenext return?

ChrisA
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/U2ELA7SS6MBDCJ6ZQSN5O324RPNSZTDK/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to