Explain how to redirect the output of a python script from standout(ie., monitor) on to a file ?


They are two possible ways of redirecting the output from standout to a file.
1. Open an output file in “write” mode and the print the contents in to that file, using sys.stdout attribute.
import sys
filename = “outputfile” sys.stdout = open() print “testing”
2. you can create a python script say .py file with the contents, say print “testing” and then redirect it to the output file while executing it at the command prompt.
Eg: has the following code:
print “Testing”
execution: python > outputfile.


© 2017