sys.stdout redirection func
Oxyd Jan 26th, 2020 85 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
- import sys
- def sprint(mytext, outfile=None):
- if outfile is None: out = sys.stdout
- else: out = open(outfile, 'w')
- try: # do some stuff
- out.write(mytext + '\n') # ...
- if outfile is not None: out.close()
- sprint('test') #write to screen
- sprint('test', 'test.log') #write to log
RAW Paste Data