3 ms·
re: logging vs. print. If you do get stuck debugging something that uses print() for all its logging, remember that in extremis you can still redirect it elsewh
by danohuiginn 17y ago
re: logging vs. print. If you do get stuck debugging something that uses print() for all its logging, remember that in extremis you can still redirect it elsewhere:
import sys
old_stdout = sys.stdout #store the real stdout
logfile = open('/some/file', 'a')
sys.stdout = logfile #redirect output to a file
#code you're debugging here
sys.stdout = old_stdout #restore the real stdout
[Obviously using logging from the start is _far_ preferable]