Skip to main content
AI Assist is now on Stack Overflow. Start a chat to get instant answers from across the network. Sign up to save and share your chats.
Just for the completeness sake, also including the package name
Source Link

Python lets you capture and assign sys.stdout - as mentioned - to do this:

import sys old_stdout = sys.stdout log_file = open("message.log","w") sys.stdout = log_file print "this will be written to message.log" sys.stdout = old_stdout log_file.close() 

Python lets you capture and assign sys.stdout - as mentioned - to do this:

old_stdout = sys.stdout log_file = open("message.log","w") sys.stdout = log_file print "this will be written to message.log" sys.stdout = old_stdout log_file.close() 

Python lets you capture and assign sys.stdout - as mentioned - to do this:

import sys old_stdout = sys.stdout log_file = open("message.log","w") sys.stdout = log_file print "this will be written to message.log" sys.stdout = old_stdout log_file.close() 
Source Link
Michael
  • 3.6k
  • 5
  • 29
  • 34

Python lets you capture and assign sys.stdout - as mentioned - to do this:

old_stdout = sys.stdout log_file = open("message.log","w") sys.stdout = log_file print "this will be written to message.log" sys.stdout = old_stdout log_file.close()