import sys sOUT = sys.stdout sERR = sys.stderr sys.stdout = open("ouput.txt", "w") sys.stderr = sys.stdout sys.stdout = sOUT sys.stderr = sERR