Skip to content

Instantly share code, notes, and snippets.

@StephenFordham
Created April 10, 2020 12:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save StephenFordham/5389bc8700477a67a137da62cfc90832 to your computer and use it in GitHub Desktop.
Save StephenFordham/5389bc8700477a67a137da62cfc90832 to your computer and use it in GitHub Desktop.
Class_decorator_example2.
class Power(object):
def __init__(self, arg):
self._arg = arg
self._memory = []
def __call__(self, a, b):
retval = self._arg(a, b)
self._memory.append(retval ** 2)
return retval ** 2
def memory(self):
return self._memory
@Power
def multiply_together(a, b):
return a * b
print(multiply_together)
print(multiply_together(2, 2))
print(multiply_together(3, 2))
print(multiply_together(2, 6))
print(multiply_together.memory())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment