Decorator function in python part2 -
def request(method="get", path="", data=none): def wrapper(func): func.routed = true func.method = method func.path = path func.data = data return func return wrapper def response(fmt="%s", contenttype="text/plain"): def wrapper(func): func.format = fmt func.contenttype = contenttype return func return wrapper @request("get", "%(channel)d/value") @response("%d") def digitalread(self, channel): self.checkdigitalchannel(channel) return self.__digitalread__(channel)
from last discussion, talked @a @b def func:
would become func=a()(b() func()) above, @request , @response wrapper how new digitalread function like?
the function have attributes given in wrappers within decorators added it.
Comments
Post a Comment