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

Technology CommunityCategory: PythonWhat does Python optimization (-O or PYTHONOPTIMIZE) do?
VietMX Staff asked 3 years ago

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