Skip to content

Instantly share code, notes, and snippets.

@ysl2
Forked from mike1026915/tee.py
Created January 16, 2022 01:46
Show Gist options
  • Save ysl2/453cbe4657ca624c858b22e17c9ee5c5 to your computer and use it in GitHub Desktop.
Save ysl2/453cbe4657ca624c858b22e17c9ee5c5 to your computer and use it in GitHub Desktop.
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