我想指出一个什么都不做的函数:
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