I want to log the output of my python file into a txt. I also want to still see it in the terminal too.
I tried using sys.stdout, but it did not still have terminal output. To log it I open my log file with f = open("log.txt", "r+")
, then set sys.stdout = f
. When the code ended, I said f.close()
to write changes. Here is some code:
import sysf = open("files/log.txt", "r+")sys.stdout = fprint("You will not see this in terminal")f.close()