Advertisement
HasteBin0

Py3 print function (2)

Jul 16th, 2020 (edited)
1,344
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.39 KB | None | 0 0
  1. #!/user/bin/python3
  2. from typing import TextIO
  3. import sys
  4.  
  5.  
  6. class PintFxnContext:
  7.     _last_stream: TextIO
  8.     _custom_stream: TextIO
  9.  
  10.     def __init__(self, out: TextIO):
  11.         self._last_stream = sys.stdout
  12.         self._custom_stream = out
  13.  
  14.     def __enter__(self):
  15.         sys.stdout = self._custom_stream
  16.  
  17.     def __exit__(self, *_):
  18.         sys.stdout = self._last_stream
  19.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement