I'm pretty new to Python so I am still just learning the language. One of the things I came across was reassigning sys.stdout to change the default output of print. So I wrote this as a test:
import sys sys.stdout = open('log.txt','a') print('hey') sys.stdout.close() sys.stdout = sys.__stdout__ print('hi')
Now the string 'hi' is not written to the file but it does not show in the default output either. When I assign some other variable to sys.stdout in the beginning and change it back it works, but I'm just wondering why its not changing back the first time.
© Stack Overflow or respective owner