来自 2.7.2 文档,第 6 节Modules
:
Passing two -O flags to the Python interpreter (-OO) will cause the bytecode compiler to perform optimizations that could in some rare cases result in malfunctioning programs. Currently only __doc__ strings are removed from the bytecode, resulting in more compact .pyo files.
这引起了我的注意:
Since some programs may rely on having these available, you should only use this option if you know what you’re doing.
在任何情况下,删除脚本的文档字符串可能会在逻辑上破坏代码功能的某些依赖性或其他方面,而忽略任何语法错误?
编辑
为什么删除评论会破坏帮助声明?在解释器中似乎没有这样做。
>>> help('import_pi')
Help on module import_pi:
NAME
import_pi
FILE
/home/droogans/py/import_pi.py
FUNCTIONS
print_pi()
DATA
pi = 3.1415926535897931
>>> import import_pi()
>>> import_pi.__doc__
>>>
>>> print import_pi.print_pi.__doc__
Convert a string or number to a floating point number, if possible.