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')
'Hey' is written to the file, but 'hi' shows up nowhere. However, this works as expected, and 'hey' is written to the file, and 'hi' is printed to the console output:
import sys
sys.__stdout__ = sys.stdout
sys.stdout = open(r'C:\Users\Vincent\Documents\Python\log.txt','a')
print('hey')
sys.stdout.close()
sys.stdout = sys.__stdout__
print('hi')
In short its a small problem that doesnt really matter too much, I am just wondering if there's a discernible reason why its not working the way it should. I have tried this on Windows 7 Home Premium with IDLE and pyscripter on v3.2.3 and my portable python v3.2.1.