Created
September 26, 2013 10:24
-
-
Save chengui/6712342 to your computer and use it in GitHub Desktop.
tee like stream for output both file and stdout
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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