Showing posts with label event handler. Show all posts
Showing posts with label event handler. Show all posts

Sunday, March 11, 2012

Using decorators and closures in python

Decorators

A decorator wraps a class or method to extend it. In python the syntax used to wrap the original function is @decoratorname. For example let's say the original function A needs to be decorated with B:
def B(a):
  def C(*args):
    return 2 * a(*args);
  return C

@B
def A(x, y):
  return x + y;

print A(2, 3)