I am trying to build decorators within decorators.
I thought I take the example I have discussed previously.
I have a function that multiplies x and y.
My decorator function just prints out a statement saying "x*y = "
I have now added a superdecorator function around my decorator function where I now want to multiply (n*x)*(n*y) i.e. if n=2 then I want to multiply the double of x and the double of y.
Here is my code below but I am getting an error message
I thought I take the example I have discussed previously.
I have a function that multiplies x and y.
My decorator function just prints out a statement saying "x*y = "
I have now added a superdecorator function around my decorator function where I now want to multiply (n*x)*(n*y) i.e. if n=2 then I want to multiply the double of x and the double of y.
Here is my code below but I am getting an error message
1 2 |
print ( '{} * {} = ' . format ( * args * n, * * kwargs * n), end = '') TypeError: unsupported operand type (s) for * : 'dict' and |
1 2 3 4 5 6 7 8 9 10 11 12 |
def superdecorator(n): def decorator(func): def wrapped( * args, * * kwargs): print ( '{} * {} = ' . format ( * args * n, * * kwargs * n), end = '') return func( * args * n, * * kwargs * n) return wrapped return decorator @superdecorator ( 2 ) def mult(x,y): return x * y |