简体   繁体   中英

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM