Marc Abramowitz added the comment:

As it happens, I wrote a similar context manager to Victor's recently for a 
setup.py because I wanted to suppress compiler errors that are output to the 
console by distutils.ccompiler.CCompiler.has_function. As Victor mentioned, for 
this to work with subprocesses, you need to go a little more low-level and mess 
around with file descriptors. Here's my function:

http://marc-abramowitz.com/archives/2013/07/19/python-context-manager-for-redirected-stdout-and-stderr/

(Maybe distutils.ccompiler.CCompiler.has_function should redirect its own 
output automatically, but that's another issue)

But then I got to thinking that it could be made a bit more powerful and the 
syntax could be a little nicer. So I have this code that I'm experimenting with:

https://gist.github.com/msabramo/6043474

But critiquing my own function, I wonder if it's trying to do too much in one 
function and it's using keyword arguments where it could be using the with 
statement better. So I might like Nick's API better.

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue15805>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to