@contextmanager
def suppress_stdout():
 with open(os.devnull, 'w') as devnull:
  old_stdout = sys.stdout
  sys.stdout = devnull
  try:
   (yield)
  finally:
   sys.stdout = old_stdout

@ contextmanager def suppress_stdout ( ) : with open ( os . devnull , 'w' ) as devnull : old_stdout = sys . stdout sys . stdout = devnull try : ( yield ) finally : sys . stdout = old_stdout
temporarily disable console output .