Last active
November 15, 2017 19:04
-
-
Save bao-qian/3ebb323bd29299da6ff7c87324321e40 to your computer and use it in GitHub Desktop.
python tee example
This file contains hidden or 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
| from contextlib import contextmanager | |
| from tee import StdoutTee, StderrTee | |
| # λ python test.py | |
| # test tee | |
| # λ cat stdout.log | |
| # test tee | |
| @contextmanager | |
| def Tee(): | |
| # must use buffer io on windows due to python 3.6 bug | |
| with StdoutTee("stdout.log", buff=1), StderrTee("stderr.log", buff=1): | |
| yield | |
| def main(): | |
| with Tee(): | |
| print('test tee') | |
| if __name__ == '__main__': | |
| main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment