Reputation: 251
I want to call a Python function y within another function x by passing on the arguments for function y, and then dynamically reset one of the parameters of function y during execution. How can I do it? Below is an example of what I'm trying to do.
def functiony(p,q,r):
return (p+q)*r
def functionx(functiony,loopvalue):
for i in loopvalue:
<<code to reset the 'r' argument of function y, keeping other arguments the same>>
print(functiony)
functionx(functiony(2,3,4),loopvalue=[10,20,30])
Upvotes: 0
Views: 349
Reputation: 12015
Instead of passing functiony
into functionx
, just pass functiony
's args into functionx
def functiony(p,q,r):
return (p+q)*r
def functionx(functiony_args,loopvalue):
for i in loopvalue:
functiony_args[1] = i
print(functiony(*functiony_args))
functionx([2,3,4],loopvalue=[10,20,30])
Upvotes: 1