sys.stndout syntax
Jeff Kunce
kuncej at mail.conservation.state.mo.us
Fri Aug 18 15:41:00 EDT 2000
> on win32, to get printed output to a file i use
> >>> sys.stndout = open('file.txt', 'w')
> how do i get it to go back to the command line
#Here is the specific solution for those who remember the secret password:
sys.stdout = open('file.txt', 'w')
print 'this is written to file.txt'
sys.stdout.close()
sys.stdout = sys.__stdout__
print 'this is written to console'
#Here is the general solution if you can't be bothered with remembering
secret passwords:
original_stdout = sys.stdout
sys.stdout = open('file.txt', 'w')
print 'this is written to file.txt'
sys.stdout.close()
sys.stdout = original_stdout
print 'this is written to console'
--Jeff
More information about the Python-list
mailing list