I tried to use this code for redirecting the error stream:
import sys
file = open("log", "w")
sys.stderr.write = file.write
variable #for raising a NameError
I tried this too:
import sys
file = open("log", "w")
sys.stderr = file
variable
The file is created but even after raising the errors there's no data inside the file. It's empty. I think so this is a bug because I saw questions on stack overflow which give the same answer but the code just doesn't work for me. Also, I'm using python 3.10.0