I want to use a function that accepts kwargs, but the argument name is being retrieved from a separate process and is unknown before hand.
kwargs
For example:
param = 'desired_param' some_function(desired_param=5)
The problem is that I don't know the content of the param and so have to somehow pass it to some_function.
param
some_function
Is it possible to pass the content of the param to the function with a value?
some_function is not something I defined, so I don't have any control over it.
Use keyword expansion:
param = 'desired_param' d = {param:5} some_function(**d)
Or even shorter:
param = 'desired_param' some_function(**{param:5})
2.1m questions
2.1m answers
60 comments
57.0k users