Python: calling a constructor from a dictionary?

I'm not quite sure of the terminology here, so please bear with me ....

Let's say I have a constructor call:

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 that I would like to replace this with a dictionary operation 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?

+4
source share
2 answers
 machineSpecificEnvironment = Environment(**keys) 
+5
source

You can use dict as an argument list with the notation **

 machineSpecificEnvironment = Environment(**keys) 
+3
source

Source: https://habr.com/ru/post/1310123/


All Articles