Skip to content

Instantly share code, notes, and snippets.

@gerritjandebruin
Created January 15, 2022 07:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gerritjandebruin/8d35fff3afd71c5b769700bc2519f252 to your computer and use it in GitHub Desktop.
Save gerritjandebruin/8d35fff3afd71c5b769700bc2519f252 to your computer and use it in GitHub Desktop.
Hide any print statement
import os
import sys
class HiddenPrints:
def __enter__(self):
self._original_stdout = sys.stdout
sys.stdout = open(os.devnull, 'w')
def __exit__(self, exc_type, exc_val, exc_tb):
sys.stdout.close()
sys.stdout = self._original_stdout
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment