Quantcast
Channel: Active questions tagged python - Stack Overflow
Viewing all articles
Browse latest Browse all 13891

How to log output of script

$
0
0

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()

Viewing all articles
Browse latest Browse all 13891

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>