便利包提供
项目描述
此包允许您进行精彩的导入
>>> 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的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | 09788971efb425716e8732a468cb015f1d6be263755f076ea8ea7a624070b900 |
|
MD5 | b5e6a422cba76248112f76e998c1c0bd |
|
BLAKE2b-256 | 88bc7e1ecec49a5cb2212b11407cba21fee26b1f34c7510b7dd530811a60b387 |