Redirects prints to file : Standard Redirect « Development « Python






Redirects prints to file

x = 99

y = "Hi"


import sys
sys.stdout = open('log.txt', 'a')     # redirects prints to file

print x, y, x                         # shows up in log.txt


           
       








Related examples in the same category

1.Link Python system error stream into a file
2.Link Python print stream into a fileLink Python print stream into a file
3.Log print message into a fileLog print message into a file
4.Map string to sys.stout.writeMap string to sys.stout.write