TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Why you should never use 'assert' in Python

2 点作者 albi_lander超过 6 年前

1 comment

ElBarto超过 6 年前
It&#x27;s nothing to do with Python, really.<p>&#x27;assert&#x27; really is a debugging tool that forces an exception and&#x2F;or a core dump on a bug condition.<p>It is standard practice to have assertions in debug builds removed in release builds.<p>Code should not use assertions to detect error cases but only bugs (i.e. conditions which should never be true whatever happens).<p>In the code discussed here they are using &#x27;assert&#x27; to check a password, which is simply bad design.<p>It&#x27;s perfectly fine to use &#x27;assert&#x27; in Python for what it is for.