我想指出一个什么都不做的函数:
def identity(*args)
return args
我的用例是这样的
try:
gettext.find(...)
...
_ = gettext.gettext
else:
_ = identity
当然,我可以使用上面定义的 identity,但是内置的运行速度肯定会更快(并且可以避免我自己引入的 bug)。
显然,map和 filter使用 None作为标识,但这是特定于它们的实现的。
>>> _=None
>>> _("hello")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: 'NoneType' object is not callable