使用optimize标志运行python有什么含义? [英] What are the implications of running python with the optimize flag?

查看:129
本文介绍了使用optimize标志运行python有什么含义?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我似乎找不到一个很好的简单解释来说明当使用-O或optimize标志运行时python的不同之处.

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

推荐答案

assert语句以及形式为if __debug__: ...的语句块都被完全消除(因此,您可以将调试代码放入此类语句块中并运行使用-O以避免该调试代码.

assert statements are completely eliminated, as are statement blocks of the form if __debug__: ... (so you can put your debug code in such statements blocks and just run with -O to avoid that debug code).

此外,使用-OO,也消除了文档字符串.

With -OO, in addition, docstrings are also eliminated.

这篇关于使用optimize标志运行python有什么含义?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆