import sys real_out = sys.stdout class MyOutput: def write(self, text): # send to web server real_out.write("good") sys.stdout = MyOutput() print "hello world"