Skip to content

Instantly share code, notes, and snippets.

@splinecraft
Created September 19, 2016 04:37
Show Gist options
  • Save splinecraft/5bc966fba4e3c08a8361acc40e09c118 to your computer and use it in GitHub Desktop.
Save splinecraft/5bc966fba4e3c08a8361acc40e09c118 to your computer and use it in GitHub Desktop.
Example of having default values and overriding them with kwargs From http://stackoverflow.com/questions/1098549/proper-way-to-use-kwargs-in-python
def testFunc( **kwargs ):
options = { 'option1' : 'default_value1',
'option2' : 'default_value2',
'option3' : 'default_value3', }
options.update(kwargs)
print options
testFunc( option1='new_value1', option3='new_value3' )
# {'option2': 'default_value2', 'option3': 'new_value3', 'option1': 'new_value1'}
testFunc( option2='new_value2' )
# {'option1': 'default_value1', 'option3': 'default_value3', 'option2': 'new_value2'}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment