[英]python: calling constructor from dictionary?
I'm not quite sure of the terminology here so please bear with me.... 我不太清楚这里的术语所以请耐心等待....
Let's say I have a constructor call like this: 假设我有一个这样的构造函数调用:
machineSpecificEnvironment = Environment(
TI_C28_ROOT = 'C:/appl/ti/ccs/4.1.1/ccsv4/tools/compiler/c2000',
JSDB = 'c:/bin/jsdb/jsdb.exe',
PYTHON_PATH = 'c:/appl/python/2.6.4',
)
except I would like to replace that by an operation on a dictionary provided to me: 除了我想通过提供给我的字典上的操作来替换它:
keys = {'TI_C28_ROOT': 'C:/appl/ti/ccs/4.1.1/ccsv4/tools/compiler/c2000',
'JSDB': 'c:/bin/jsdb/jsdb.exe',
'PYTHON_PATH': 'c:/appl/python/2.6.4'}
machineSpecificEnvironment = Environment(
... what do I put here? it needs to be a function of "keys" ...
)
How can I do this? 我怎样才能做到这一点?
machineSpecificEnvironment = Environment(**keys)
您可以通过**表示法将dict应用为参数列表
machineSpecificEnvironment = Environment(**keys)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.