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.
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: redirect_output.py has the following code:
execution: python redirect_output.py > outputfile.