原文 : https://cloud.tencent.com/developer/ask/188486

 

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

 

相关文章:

  • 2021-08-11
  • 2022-02-09
  • 2021-07-20
  • 2022-12-23
  • 2021-12-06
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-02-09
  • 2021-11-21
  • 2022-12-23
  • 2021-07-28
  • 2021-10-02
相关资源
相似解决方案