Mega Code Archive
Sys module has the stdout and stderr attributes that point to files used for standard output and standard error output
import sys
sOUT = sys.stdout
sERR = sys.stderr
sys.stdout = open("ouput.txt", "w")
sys.stderr = sys.stdout
sys.stdout = sOUT
sys.stderr = sERR