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

2013年10月15日 10:54:14 -0700

On 10/15/2013 09:28 AM, PJ Eby wrote:
On Tue, Oct 15, 2013 at 11:52 AM, R. David Murray wrote:
What about making the context manager provide the trapped exception,
in a fashion similar to what assertRaises does?
Sadly, that won't work, since context managers provide a value
*before* the block is executed, not after.
However, if the CM provides the value before, and the with block accepts it, it 
can then have the exception added to it:
 with trap(OSError) as cm:
 os.unlink('missing.txt')
 if cm.exc:
 do_something()
--
~Ethan~
_______________________________________________
Python-Dev mailing list
[email protected]
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com

Reply via email to