1
基於類的裝飾屬性可以說我有一類爲基礎的裝飾,像這樣的說法:訪問以參數
class Decorator:
def __init__(self, arg):
self.arg = arg
def __call__(self, func):
def wrap():
# something with self.arg
func()
return wrap
當我有一個裝飾功能foo
,我能做到以下幾點:
deco = Decorator("ARG")
def foo():
pass
foo = deco(foo)
deco.arg = "CHANGE ARG"
以某種方式訪問/更改deco.arg
如果我使用@
-Syntax?
@Decorator("ARG")
def foo():
pass
# How to change/access the arg-attribute?
@Robert_Jordan沒有問題:) – MSeifert