What are the implications of running python with the optimize flag?

前端 未结 4 1171
感情败类
感情败类 2020-12-30 19:46

I cannot seem to find a good simple explanation of what python does differently when running with the -O or optimize flag.

4条回答
  •  一整个雨季
    2020-12-30 20:01

    As answered in python optimization mode:

    python -O does the following currently:

    • completely ignores asserts
    • sets the special builtin name __debug__ to False (which by default is True)

    and when called as python -OO

    • removes docstrings from the code

    I don't know why everyone forgets to mention the __debug__ issue; perhaps it is because I'm the only one using it :) An if __debug__ construct creates no bytecode at all when running under -O, and I find that very useful.

提交回复
热议问题