'Pass parameter name to a function in python

Thank you for your time reading this question.

I want to use an existing function through a PIPELINE. I want to give the name of the parameter into that pipeline as well as its value.

How can I pass the name of the parameter into a that function?

Like:

parm_name = "age"
value  = 33
foo (parm_name=value)

instead we do:

params = {'age': [11, 23, 33]}
pipeline(foo, params)

So, I have to define my pipeline function. But I don't know how to pass parameter names inside a string.

Thank you dear. Happy coding.



Solution 1:[1]

You can go with this

parm_name = "age"
value  = 33
d = {param_name: value}
foo(**d)

We can create dictionary with param nam as strings and there value and when we call **d its called unpacking so this will transform to param_name=value while calling the function.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Deepak Tripathi