类似于这样:
import sys f = open('output.txt', 'a') sys.stdout = f sys.stderr = f print("hello",file=f) f.close()