Created
September 19, 2016 04:37
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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