Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import sys
- temp = sys.stdout # store original stdout object for later
- sys.stdout = open('log.txt', 'w') # redirect all prints to this log file
- print("testing123") # nothing appears at interactive prompt
- print("another line") # again nothing appears. it's written to log file instead
- sys.stdout.close() # ordinary file object
- sys.stdout = temp # restore print commands to interactive prompt
- print("back to normal") # this shows up in the interactive prompt
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement