1import os, sys
2
3class HiddenPrints:
4 def __enter__(self):
5 self._original_stdout = sys.stdout
6 sys.stdout = open(os.devnull, 'w')
7
8 def __exit__(self, exc_type, exc_val, exc_tb):
9 sys.stdout.close()
10 sys.stdout = self._original_stdout
11
12with HiddenPrints():
13 print("This wont print")