Skip to content

Instantly share code, notes, and snippets.

Created Jun 10, 2014
What would you like to do?
from functools import wraps
class MyDecorator(object):
would normally be my_decorator because it's a function, and functions use underscore delimited lower-case.
Used CamelCase to demo that it's really a class.
def __init__(multiplier):
self.multiplier = multiplier
def __call__(func):
def wrapper(*args, **kwargs):
return self.multiplier * func(*args, **kwargs)
return wrapper
def foo():
return 4
def bar():
return 5
assert(foo() == 12)
assert(bar() == 20)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment