A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from http://mail.python.org/pipermail/python-dev/2013-October/129615.html below:

[Python-Dev] cpython: Rename contextlib.ignored() to contextlib.ignore().

[Python-Dev] cpython: Rename contextlib.ignored() to contextlib.ignore(). [Python-Dev] cpython: Rename contextlib.ignored() to contextlib.ignore().Ethan Furman ethan at stoneleaf.us
Wed Oct 16 00:41:33 CEST 2013
On 10/15/2013 12:59 PM, Tim Delaney wrote:
> On 16 October 2013 05:17, Alexander Belopolsky <alexander.belopolsky at gmail.com <mailto:alexander.belopolsky at gmail.com>>
> wrote:
>
>     On Tue, Oct 15, 2013 at 12:45 PM, Ethan Furman <ethan at stoneleaf.us <mailto:ethan at stoneleaf.us>> wrote:
>     >     with trap(OSError) as cm:
>     >         os.unlink('missing.txt')
>     >     if cm.exc:
>     >         do_something()
>
>     .. and why is this better than
>
>     try:
>         os.unlink('missing.txt')
>     except OSError as exc:
>         do_something()
>
>
> It would allow you to perform a series of operations then process the any exceptions all together e.g.
>
> with trap(OSError) as cm1:
>      os.unlink('missing.txt')
>
> with trap(OSError) as cm2:
>      os.unlink('other_missing.txt')
>
> with trap(OSError) as cm3:
>      os.unlink('another_missing.txt')
>
> for cm in (cm1, cm2, cm3):
>      if cm.exc:
>          do_something(cm.exc)


As long as we're having fun ;)

     trap_os = suppress(OSError)
     dead_files = ('missing.txt', 'other_missing.txt', 'actually_here.txt')

     for file in dead_files:
         with trap_os:
             os.unlink(missing.txt)

     for exc in trap_os.suppressed_exceptions:
         do_something(exc)

--
~Ethan~
More information about the Python-Dev mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4