Hi,
There is the __debug__ builtin variable which is equal to True by
default, but is equal to False when Python is run with the -O command
line option.
The compiler removes dead code when -O is used. Example:
$ cat x.py
def func():
if __debug__: print("debug")
import dis
dis.dis(func)
# "debug" constant is checked at runtime
$ python3 x.py
2 0 LOAD_GLOBAL 0 (print)
2 LOAD_CONST 1 ('debug')
4 CALL_FUNCTION 1
6 POP_TOP
8 LOAD_CONST 0 (None)
10 RETURN_VALUE
# code removed by the compiler
$ python3 -O x.py
2 0 LOAD_CONST 0 (None)
2 RETURN_VALUE
Victor
Le mer. 21 oct. 2020 à 14:21, Marco Sulla
<Marco.Sulla.Python@gmail.com> a écrit :
>
> If not already present, do you think it's useful to add a macro that does something like
>
> # ifdef Py_DEBUG
> fprintf(stderr, "%s\n", message);
> # endif
>
> ?
> _______________________________________________
> Python-Dev mailing list -- python-dev@python.org
> To unsubscribe send an email to python-dev-leave@python.org
> https://mail.python.org/mailman3/lists/python-dev.python.org/
> Message archived at https://mail.python.org/archives/list/python-dev@python.org/message/6W6YO6JSJZOGWYWNWB2ARUS4LSLY3C7Y/
> Code of Conduct: http://python.org/psf/codeofconduct/
--
Night gathers, and now my watch begins. It shall not end until my death.
_______________________________________________
Python-Dev mailing list -- python-dev@python.org
To unsubscribe send an email to python-dev-leave@python.org
https://mail.python.org/mailman3/lists/python-dev.python.org/ Message archived at
https://mail.python.org/archives/list/python-dev@python.org/message/5V3HNOGDF2I44CKEAYR2XILF6DE7THFL/ Code of Conduct:
http://python.org/psf/codeofconduct/