3 ms·
Most people don't know that Python has a '-O' optimize CLI option: $ python -h usage: python [option] ... [-c cmd | -m mod | file | -] [arg] ... Op
by carapace 8y ago
Most people don't know that Python has a '-O' optimize CLI option:
$ python -h
usage: python [option] ... [-c cmd | -m mod | file | -] [arg] ...
Options and arguments (and corresponding environment variables):
...
-O : optimize generated bytecode slightly; also PYTHONOPTIMIZE=x
-OO : remove doc-strings in addition to the -O optimizations
...
It does two things (that I know of):
1.) Assertions are removed. The assertion code does not appear in the bytecode.
2.) Any code guarded by a "if __debug__:" statement is also removed.
YMMV