How to depress the output of an external module ?

Luis Armendariz luis at geodynamics.org
Tue Dec 26 06:21:57 EST 2006


On Tuesday, 26.12.06 at 21:28, Steven D'Aprano wrote:
> 
> # WARNING: untested
> def run_without_stdout(*args, **kwargs):
>     function = args[0]
>     args = args[1:]
>     savestdout = sys.stdout
>     sys.stdout = cStringIO.StringIO()
>     result = None
>     try:
>         result = function(*args, **kwargs)
>     finally:
>         # don't forget to restore stdout, or you 
>         # really will regret it...
>         sys.stdout = savestdout
>     return result
> 

There's no need for savestdout. There's a backup copy in sys.__stdout__
-Luis



More information about the Python-list mailing list