0

I'm a student learning python and have very low knowledge of coding. Please forgive my stupidity, question might not even make sense.

I'm trying to make a log text file with the printed result of the program.

And I tried using,

with open('textfile.txt', 'a') as f:
    sys.stdout = f        
    print(result)
    sys.stdout = original_stdout

Actually, it worked and successfully appended result to the text file, BUT I couldn't see printed result on the program.

How can I make the result visible on the running screen and append to the text file at the same time?

Also, there are many print statement through the script and I put above script on every bunch of them. Am I doing right?

Is there simpler way to append all print statement to a text file?

Sean Kwon
  • 11
  • 2

0 Answers0