I need to forward a dictionary to another function (that I can't change). Both my function and the target function look like this:
def myFunc(arg, **args):
def targetFunc(arg, **args):
In my code, I used to call the target function directly:
a = targetFunc(123, aaa=4, bbb=5, ccc=6)
and I have to add another layer to process the extra arguments passed as a dictionary, before forwarding to the target function:
a = myFunc(123, aaa=4, bbb=5, ccc=6)
And now my function receives 123
as arg
, and a dictionary:
{'bbb": 5, 'ccc': 6, 'aaa': 4}
as args
. The problem is, I can't modify the target function in any way. It may be a function from a package like subprocess.run
. I've tried supplying the dictionary directly but Python says
def myFunc(arg, **args):
print(args)
targetFunc(arg, args)
def targetFunc(arg, **args):
print(args)
TypeError: targetFunc() takes 1 positional argument but 2 was given
I can write myFunc
in any way. How can I forward this dictionary to the target function, so it receives the same dictionary as its args
?
Note: It's possible to construct a string then eval()
it, but I don't want to do it that way.