python中的shield(invalidate)断言

2024-10-05 11:24:53 发布

您现在位置:Python中文网/ 问答频道 /正文

我想在Python代码中将“assert”作为发行版运行时使其无效。考虑到在开发过程中我的文件中可能会用到很多assert,但是为了提高效率,我想跳过assert的编译。有没有一些简单的方法,比如在c++中预先定义“NDEBUG”


Tags: 文件方法代码定义过程assert中将提高效率
1条回答
网友
1楼 · 发布于 2024-10-05 11:24:53

使用命令行选项-O。如the docs所述:

In the current implementation, the built-in variable __debug__ is True under normal circumstances, False when optimization is requested (command line option -O). The current code generator emits no code for an assert statement when optimization is requested at compile time.

相关问题 更多 >

    热门问题