dbm 实例为 false

发布于 2025-01-01 09:35:39 字数 184 浏览 4 评论 0原文

在 python 2.6.5 中,dbm 的实例没有 __nonzero__ 或 __len__ 方法,那么为什么它会将 false 计算为布尔值呢?

>>> a = dbm.open( 'foo', 'c' )
>>> if a: print 'true'
...
>>>

In python 2.6.5, an instance of dbm does not have a __nonzero__ or a __len__ method, so why does it evaluate false as a boolean?

>>> a = dbm.open( 'foo', 'c' )
>>> if a: print 'true'
...
>>>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

哆兒滾 2025-01-08 09:35:39

根据python文档,值的类型之一是被认为是假的是

任何空映射,例如 {}

由于dbm对象是一个映射并且新实例是空的,因此它是错误的。

According to the python documentation one of the types of values that is considered false is

any empty mapping, for example, {}.

Since a dbm object is a mapping and a new instance is empty, it is therefore false.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文