What does the -O flag do?

"Martin v. Löwis" martin at v.loewis.de
Tue Jan 9 17:53:25 EST 2007


Sard schrieb:
> "Optimize generated bytecode (also PYTHONOPTIMIZE=x). Asserts are
> suppressed."
> 
> Is removing asserts all it does, where can I find more details?  I'm
> guessing it's not very useful as I hardly ever see it mentioned.

It somewhat depends on the Python version. To find out precisely what
it does, search the source code for Py_OptimizeFlag. In 2.5, it

- causes the interpreter to load .pyo files, not .pyc files
  (in .zip files, just makes .pyo preferred over .pyc)
- causes __debug__ to have a value of 0
- ignores assert statements in source code
- treats __debug__ statically as being 0
- causes the byte code generator to save .pyo files, not .pyc

HTH,
Martin



More information about the Python-list mailing list