How to catch python's STDOUT

Fredrik Lundh fredrik at pythonware.com
Thu Apr 6 05:27:29 EDT 2006


praveenkumar.117 at gmail.com wrote:

>        Can someone help me by suggesting how to capture python's
> STDOUT. I doesn't want the python's output to get displayed on the
> screen.

you can replace sys.stdout (and/or sys.stderr) with your own file-like
object, e.g.

    class NullStream:
        def write(self, text):
            pass

    import sys
    sys.stdout = NullStream()

if this doesn't solve your problem, you have to be a bit more specific
(since in general, python doesn't print anything unless you ask it to...)

hope this helps!

</F>






More information about the Python-list mailing list