Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Tee with Python
import sys
class Tee(object):
def __init__(self, name, mode):
self.file = open(name, mode)
self.stdout = sys.stdout
sys.stdout = self
def __del__(self):
sys.stdout = self.stdout
self.file.close()
def write(self, data):
self.file.write(data)
self.stdout.write(data)
log1 = Tee('a.log', 'w')
print '123'
log1.__del__()
log2 = Tee('b.log', 'w')
print '456'
log2.__del__()
log3 = Tee('c.log', 'w')
print '789'
log3.__del__()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.