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()
1. | Link Python system error stream into a file | ||
2. | Log print message into a file | ||
3. | Map string to sys.stout.write | ||
4. | Redirects prints to file |