A note about [python] __debug__

Note

debug_print.py


def debug_print(s):
    if not __debug__:
        print(s)

If you make it like this,

test.output


$ python -c '(__import__)("debug_print").debug_print(__debug__)'
$ python -O -c '(__import__)("debug_print").debug_print(__debug__)'
False

Like, it is printed only when the -O option is added.

Recommended Posts

A note about [python] __debug__
Python: A Note About Classes 1 "Abstract"
A note about mock (Python mock library)
A note about __call__
A note about subprocess
A note about mprotect (2)
A note about the python version of python virtualenv
Data analysis in Python: A note about line_profiler
A note about KornShell (ksh)
A memorandum about correlation [Python]
A note about TensorFlow Introduction
A memorandum about Python mock
Note: Python
Python Note: About comparison using is
A note about get_scorer in sklearn
A note about hitting the Facebook API with the Python SDK
About python slices
About python comprehension
Python study note_002
Note: Python Decorator
A note where a Python beginner got stuck
[Python] Learning Note 1
About Python tqdm.
About python yield
About python, class
Python study note_004
A Java programmer studied Python. (About type)
About python inheritance
About python, range ()
Python study note_003
About python decorators
[Note] openCV + python
A story about Python pop and append
Note about awk
Just a note
About python reference
About Python decorators
[Python] About multi-process
Python beginner's note
About February 02, 2020 * This is a Python article.
A note about doing the Pyramid tutorial
A Java programmer studied Python. (About functions (methods))
A Java programmer studied Python. (About the decorator)
[Note] Create a one-line timezone class with python
A note on optimizing blackbox functions in Python
A memo about writing merge sort in Python
A simple Pub / Sub program note in Python
Python Note: When assigning a value to a string
A story about running Python on PHP on Heroku
Think about building a Python 3 environment in a Mac environment
A memorandum about the Python tesseract wrapper library
[Note] About the role of underscore "_" in Python
A note about the new style base class
A note about checking modifiers with Max Plus
A story about modifying Python and adding functions
A * algorithm (Python edition)
About function arguments (python)
[Python] Take a screenshot
[Note] future sentence ~ Python ~
[Note] File reading ~ Python ~
A python lambda expression ...