[英]Passing list as normal arguments to function in python
Say I have some code like this: 说我有一些这样的代码:
d = {'range': range}
args = [10]
d['range'](args)
args will be of variable content and length. args具有可变的内容和长度。 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.
我可以处理可能引发的任何异常...我不能更改正在调用的函数(range是内置的),最好不要包装它。 How can I make this code function properly?
如何使此代码正常运行?
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]
>>>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.