The Python call function can provide a value that Key=value represents this parameter, and we can call the function without the order of the function definition .... (*A,**B) can be used as an adorner to provide indeterminate parameters ... Greatly reducing the coupling of the adorner and the decorated function def func (): Return 1///Returns the name of the function func.__name__//////the static method of implementing the class with the Adorner class class: @st Aticmethod def OK (): print "OK" class.ok ()/////indeterminate parameter adorner #encoding =utf-8def Deco (func): Def _infunc (*args,**kva RGS): Print ("before MyFunc () called.") Func (*args,**kvargs) print ("After MyFunc () called.") Return _infunc@decodef MyFunc (A, b): print "a+b=", A+b@decodef MyFunc1 (a,b,c): print "a+b+c=", A+b+cmyfunc MyFunc1 ( b=1,a=100,c=8)////decorator with parametric #encoding=utf-8def Decco (ARG): Def _deco (func): Def _infunc (*args,**kvargs): Print ("Before MyFunc () called. args:%s "% arg" func (*args,**kvargs) print ("After MyFunc () called.args:%s"% arg) return _inf UNC return _deco@decco ("AAA") def MyFunc (A, b): print "a+b=", A+b@decco ("BBB") def MyFunc1 (a,b,c): print "a+b+c=", a+b +c MyFunc (MyFunc1) (b=1,a=100,C=8)
A simple and practical decorator for Python