-
-
Save ysl2/453cbe4657ca624c858b22e17c9ee5c5 to your computer and use it in GitHub Desktop.
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
import sys | |
class Tee(object): | |
def __init__(file_name, mode): | |
self._file = open(file_name, mode) | |
def __enter__(self): | |
return self | |
def __exit__(self): | |
self.__close() | |
def __flush(self): | |
sys.stdout.flush() | |
self._file.flush() | |
def __close(self): | |
self.flush() | |
def write(self, data): | |
sys.stdout.write(data) | |
self._file.write(data) | |
def writeln(self, data): | |
self.write(data + "\n") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment