How to catch python's STDOUT

Greg Ewing greg at cosc.canterbury.ac.nz
Tue Aug 1 00:11:07 EDT 2006


praveenkumar.117 at gmail.com wrote:

>         I dont want the outputs of print to be displayed on the console
> since it is used my fellow-workers
>         But i need those prints for debugging purpose

import sys
sys.stdout = open("my_debugging_output.txt", "w")

Or you can replace sys.stdout with any object having
a write() method which does whatever you want with
the output.

You can similarly replace sys.stderr to capture
output written to standard error.

-- 
Greg Ewing, Computer Science Dept,
University of Canterbury,	
Christchurch, New Zealand
http://www.cosc.canterbury.ac.nz/~greg



More information about the Python-list mailing list