1
我想了解Python裝飾器。我以爲不知何故我理解裝飾器,直到我寫這個代碼。python裝飾器如何在此代碼上工作?
def func():
def wrapper(x):
return x()
return wrapper
@func()
def b():
return sum
a = b([1,2,5])
print a # Result: 8 How?
e = b # pass b function to variable e
f = e([3,4,8]) # called function b stored in variable e
print f # Result: 15
# I understand how 15 is derived here
我認爲谷歌給出了最好的答案。 https://realpython.com/blog/python/primer-on-python-decorators/ –