我嘗試使用以下代碼創建裝飾器。Python修飾符錯誤?
def outer():
def inner():
print 'inner called'
return inner
foo = outer()
foo()
但它給
TypeError: 'NoneType' object is not callable
請解決我的問題的錯誤。謝謝..
我嘗試使用以下代碼創建裝飾器。Python修飾符錯誤?
def outer():
def inner():
print 'inner called'
return inner
foo = outer()
foo()
但它給
TypeError: 'NoneType' object is not callable
請解決我的問題的錯誤。謝謝..
我相信這是你想要的代碼:
def outer():
def inner():
print 'inner called'
return inner
foo = outer()
foo()
你return
太遠
此外縮進,是一個裝飾,'outer'應該好好裝飾作爲參數的函數。 –
是的,這不是一個真正的裝飾器,它現在只是一個包裝函數 – jamylak
對不起,它真的是包裝函數。 – dhana