4

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?

Jason S
  • 184,598
  • 164
  • 608
  • 970

2 Answers2

5
machineSpecificEnvironment = Environment(**keys)
Duncan
  • 92,073
  • 11
  • 122
  • 156
  • 1
    In the documentation *duck* http://docs.python.org/tutorial/controlflow.html#keyword-arguments http://docs.python.org/tutorial/controlflow.html#unpacking-argument-lists – Rudi May 18 '10 at 14:29
  • various places, but the problem is knowing what to look for (and even then since there's no keyword it's tricky to search). Try http://docs.python.org/reference/expressions.html#calls for the formal function call syntax. – Duncan May 18 '10 at 14:31
3

You can apply a dict as an argument list by the ** notation

machineSpecificEnvironment = Environment(**keys)
Rudi
  • 19,366
  • 3
  • 55
  • 77