Skip to content

Instantly share code, notes, and snippets.

@chengui
Created September 26, 2013 10:24
Show Gist options
  • Save chengui/6712342 to your computer and use it in GitHub Desktop.
Save chengui/6712342 to your computer and use it in GitHub Desktop.
tee like stream for output both file and stdout
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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment