メモ
*ただのメモです
__debug__
これは組み込み定数ひとつで、python実行の際に-O
をつけるとFalse
、じゃなければTrue
となる定数。(これ、 大文字のオー,ゼロじゃない)
debug_print.py
def debug_print(s):
if not __debug__:
print(s)
こんな感じで作ると、
test.output
$ python -c '(__import__)("debug_print").debug_print(__debug__)'
$ python -O -c '(__import__)("debug_print").debug_print(__debug__)'
False
のように、-O
オプションをつけた時だけprintされます。