python save console output to file code example
Example 1: python export console output to file
sys.stdout = open("test.txt", "w")
print("Hello World")
sys.stdout.close()
# TEST.TXT:
# Hello World
Example 2: save python output to text file
$ python my_program.py > output.txt