The following code I got from http://forums.devshed.com/python-programming-11/redirect-stdout-stderr-file-500952.html which tells how to redirect a stderr to a file. I tried it but the error message is not getting saved to the file. While I am not using
sys.stderr = file_err
the error is displayed in the idle terminal, when I am assigning file_err to sys.stderr the error is not displayed in the idle terminal, and it is not being copied to the file_name.log
import sys
original_stderr = sys.stderr
file_err = open('file_name.log', 'w') # I tried with .txt also
sys.stderr = file_err
print(list[file]) # Used to create a NameError
sys.stderr = original_stderr
file_err.close()
Am I supposed to write it to the file or is there an error in the program?