跳转到主要内容

便利包提供

项目描述

此包允许您进行精彩的导入

>>> from nihilo import nihil

这是一个表现像None但接受方法调用的良好对象。您为什么想这么做呢?

所以,我们有

>>> a_dict = { 'who': 'Parmenides' }
>>> print a_dict.get('who')
Parmenides
>>> print a_dict.get('where')
None
但您可能想这么做
>>> a_dict.get('who').startswith('g')
False
>>> a_dict.get('where').startswith('g')
Traceback (most recent call last):
...
AttributeError: 'NoneType' object has no attribute 'startswith'
使用虚无,您可以这样做
>>> print a_dict.get('where', nihil).startswith('g')
nihil()

请注意,转换为bool会返回false,因此您可以轻松测试...

>>> if a_dict.get('where', nihil).startwith('g'):
...   print "got it!"

虚无非常灵活,它还将允许您调用几乎任何方法,并将返回自身

>>> nihil.foo.bar('quux', frop=True)
nihil()

而且请记住,从无中生有,无物可成。

项目详情


下载文件

下载适用于您平台的文件。如果您不确定选择哪个,请了解更多关于安装包的信息。

源分布

nihilo-0.1.tar.gz (652 字节 查看哈希值)

上传时间:

由以下支持

AWS AWS 云计算和安全赞助商 Datadog Datadog 监控 Fastly Fastly CDN Google Google 下载分析 Microsoft Microsoft PSF 赞助商 Pingdom Pingdom 监控 Sentry Sentry 错误记录 StatusPage StatusPage 状态页面