Link Python print stream into a file : Standard Redirect « Development « Python






Link Python print stream into a file

Link Python print stream into a file
import sys

print 'Dive in'
saveout = sys.stdout
fsock = open('out.log', 'w')
sys.stdout = fsock
print 'This message will be logged instead of displayed'
sys.stdout = saveout
fsock.close()


           
       








Related examples in the same category

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