Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

python hide print output

# credit to user in Stack Overflow

import os, 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
        
with HiddenPrints():
  print('Will not be printed')
 
print('Will be printed')
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #python #hide #print #output
ADD COMMENT
Topic
Name
1+4 =