以某種方式,您也可以看到一些operator
函數。
例如,operator.itemgetter()
以這種方式工作:
import operator
get1 = operator.itemgetter(1) # creates a function which gets the item #1 of the given object
get1([5,4,3,2,1]) # gives 4
這通常被用來即G。作爲排序函數等的函數。
如果您有一個具體的問題可以解決,那麼您可以輕鬆地想到類似的,更具體的用例。
在同一聯賽你有這些「裝飾創造者」:
def indirect_deco(outer_param):
def real_deco(func):
def wrapper(*a, **k):
return func(outer_param, *a, **k)
return wrapper
return real_deco
@indirect_deco(1)
def function(a, b, c):
print (((a, b, c))
function(234, 432)
同樣在這裏,外部函數是一個工廠函數創建了「真正的裝飾」功能。反過來,這甚至會創建另一個代替最初給定的代理。
「相同」相比什麼? – glglgl