Created
September 13, 2015 08:50
-
-
Save cyberbikepunk/471b7e8358fb4c9a0c87 to your computer and use it in GitHub Desktop.
use a class instance to make a decorator
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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