What does Python optimization (-O or PYTHONOPTIMIZE) do?

后端 未结 1 1946
佛祖请我去吃肉
佛祖请我去吃肉 2020-11-29 04:45

The docs only say that Python interpreter performs \"basic optimizations\", without going into any detail. Obviously, it\'s implementation dependent, but is there any way to

相关标签:
1条回答
  • 2020-11-29 05:06

    In Python 2.7, -O has the following effect:

    • the byte code extension changes to .pyo
    • sys.flags.optimize gets set to 1
    • __debug__ is False
    • asserts don't get executed

    In addition -OO has the following effect:

    • sys.flags.optimize gets set to 2
    • doc strings are not available

    To verify the effect for a different release of CPython, grep the source code for Py_OptimizeFlag.

    Link to official documentation: https://docs.python.org/2.7/tutorial/modules.html#compiled-python-files

    0 讨论(0)
提交回复
热议问题