我想指出一个什么都不做的函数:
def identity(*args)
return args
我的用例是这样的
try:
gettext.find(...)
...
_ = gettext.gettext
else:
_ = identity
当然,我可以使用identity上面定义的方法,但是内置方法肯定会运行得更快(并避免我自己引入的错误)。
显然,map与filter使用None的身份,但这是具体到它们的实现。
>>> _=None
>>> _("hello")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: 'NoneType' object is not callable
map(None, [1, 2, 3])
map and filter use None for the identity?