Silent the stdout of a function in python without trashing sys.stdout and restoring each function ca

Posted by Tim McJilton on Stack Overflow See other posts from Stack Overflow or by Tim McJilton
Published on 2010-05-13T17:37:52Z Indexed on 2010/05/13 17:44 UTC
Read the original article Hit count: 168

Filed under:
|

Is there a way in python without wrapping a function call like following?

from sys import stdout
from copy import copy
tempstdout = copy(stdout)
stdout = file("trash",w)
foo()
stdout = tempstdout

That way works but appears to be terribly inefficient. There has to be a better way... I would appreciate any insight I can get into this.

© Stack Overflow or respective owner

Related posts about python

Related posts about stdout