Skip to content

Instantly share code, notes, and snippets.

@cyberbikepunk
Created September 13, 2015 08:50
Show Gist options
  • Save cyberbikepunk/471b7e8358fb4c9a0c87 to your computer and use it in GitHub Desktop.
Save cyberbikepunk/471b7e8358fb4c9a0c87 to your computer and use it in GitHub Desktop.
use a class instance to make a decorator
# Write a tracer decorator
class Tracer():
def __init__(self):
pass
def __call__(self, f):
def wrapper(*args, **kwargs):
print('Called function %s' % f.__name__)
return f(*args, **kwargs)
return wrapper
tracer = Tracer()
tracer
@tracer
def rotate(list_):
rotated = [list_[-1]] + list_[0:-1]
print(rotated)
if rotated[-1] != 0:
rotate(rotated)
my_list = list(range(0,6))
rotate(my_list)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment