[Python-ideas] A different kind of context manager

Antony Lee anntzer.lee at gmail.com
Tue Oct 22 02:18:22 CEST 2013


You can get the desired behavior by (ab)using function decorators, by 
rewriting

with as_subprocess():
>
>     do_stuff()
>
as

@as_subprocess
def _():
   <do stuff>

Yes, it's not very elegant syntactically but gets the work done (and this 
technique is generalizable to most uses of Ruby-style blocks, I believe).

Antony
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20131021/cd6d8efd/attachment.html>


More information about the Python-ideas mailing list