I’m trying to construct a decorator in Python where I add a variable at the decoration stage. I know how to write a decorator where I simply run a function on the results of another function, but I’m having trouble with the syntax of adding an additional variable. Essentially, I want to take this dot product function:
def dot(x,y):
temp1=[]
for i in range(len(x)):
temp1.append(float(x[i])*y[i])
tempdot=sum(temp1)
return tempdot
and subtract the value ‘b’ from the result, all in one larger function given parameters x,y,b
Am I trying to misuse the decoration functionality in this case? Thanks.
Then use it as
By the way your dot function can be shorted with a generator expression like so: