why python decorators rather closures?
i still haven't got conduct around decorators python.
i've already started controlling lot closures things customize functions classes coding.
eg.
class node :
def __init__(self,val,children) :
self.val = val
self.children = children
def makerunner(f) :
def run(node) :
f(node)
x node.children :
run(x)
relapse run
tree=node(1,[node(2,[]),node(3,[node(4,[]),node(5,[])])])
def pp(n) : imitation "%s," % n.val
printtree = makerunner(pp)
printtree(tree)
as distant i see, decorators only opposite syntax doing something similar.
instead
def pp(n) : imitation "%s," % n.val
printtree = makerunner(pp)
i :
@makerunner
def printtree(n) : imitation "%s," % n.val
is there decorators? there component inadequacy i've missed?
Comments
Post a Comment