LoginSignup
9
6

More than 5 years have passed since last update.

標準出力を黙らせるデコレーター

Posted at

logging使うまでもないけどちょっとデバッグコメント黙らせたい時などに一時的にstdoutをdevnullするデコレーター

debug.py
def mute(func):
    def _f(*args, **kwargs):
        sys.stdout = open(os.devnull, 'w')
        res = func(*args, **kwargs)
        sys.stdout.close()
        sys.stdout = sys.__stdout__
        return res
    return _f

参考: デコレータで楽にcProfileする
http://qiita.com/mojaie/items/e14c3db9f8fdec896f8a

9
6
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
9
6