I'd like to set the optimize flag (python -O myscript.py
) at runtime within a python script based on a command line argument to the script like myscript.py --optimize
or myscript --no-debug
. I'd like to skip assert
statements without iffing all of them away. Or is there a better way to efficiently ignore sections of python code. Are there python equivalents for #if
and #ifdef
in C++?
相关问题
- how to define constructor for Python's new Nam
- streaming md5sum of contents of a large remote tar
- How to get the background from multiple images by
- Evil ctypes hack in python
- Correctly parse PDF paragraphs with Python
-O
is a compiler flag, you can't set it at runtime because the script already has been compiled by then.Python has nothing comparable to compiler macros like
#if
.Simply write a
start_my_project.sh
script that sets these flags.