Reputation: 317
Say I have some code like this:
d = {'range': range}
args = [10]
d['range'](args)
args will be of variable content and length. I can handle any exceptions this would throw... I can't change the function I'm calling (range is builtin), and it would be preferable to not wrap it. How can I make this code function properly?
Upvotes: 0
Views: 54
Reputation:
The functionality that you are looking for is called argument unpacking:
>>> d = {'range': range}
>>> args = [10]
>>> d['range'](*args)
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
>>>
Upvotes: 6