Discuss / Python / 不理解这句话,有大佬解惑吗?

不理解这句话,有大佬解惑吗?

Topic source

脑洞开天

#1 Created at ... [Delete] [Delete and Lock User]

我们来剖析上面的语句,首先执行log('execute'),返回的是decorator函数,再调用返回的函数,参数是now函数,返回值最终是wrapper函数。

我只看到了返回*decorator * 函数,没看到在哪里有调用返回函数啊??

默湾

#2 Created at ... [Delete] [Delete and Lock User]
>>> now = log('execute')(now)

因为这里now等于是log('execute')(now),前半段log('execute')首先等于decorator,那么现在加上后半段相当于decorator (now),返回值就是wrapper。


  • 1

Reply