ConfigParser and options

Laura Creighton lac at strakt.com
Thu Feb 13 00:04:54 EST 2003


first you need a dictionary of default values.
then you need a dictionary of the new values that the user wants.
then you use the update method of the dictionary to overwrite the
old values with the new values.  Then you use the apply function
to pass the updated function to whatever you like:

>> defaultDict={'d1':0, 'd2':0, 'd3':0}
>>> userDict={'d2':1}  # you could add 'd4':1 and all the not defaults
>>>                    # the user has to supply as well

>>> defaultDict.update(userDict) # if you need to keep defaults
                                 # around make a copy, because
>>> defaultDict    
{'d1': 0, 'd3': 0, 'd2': 1}      # right now its _changed_
>>> userDict
{'d2': 1}
>>>

Now myFunction(*args, **default_dict): 

is the same as myFunction(arg1, arg2, d1=0, d2=1, d3=0)

see:
http://www.python.org/doc/current/lib/built-in-funcs.html#l2h-4

HTH,
Laura







More information about the Python-list mailing list