Is there a way to save all of the print output to a txt file in python? Lets say I have the these two lines in my code and I want to save the print output to a file named
Another Variation can be... Be sure to close the file afterwards
import sys file = open('output.txt', 'a') sys.stdout = file print("Hello stackoverflow!") print("I have a question.") file.close()