Created
April 18, 2014 17:31
-
-
Save ericleong/11055297 to your computer and use it in GitHub Desktop.
Map Constructor Keyword Arguments to Object Fields
This file contains 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
class Thing: | |
def __init__(self, **kwargs): | |
# Set fields according to their name in the arguments | |
for name, value in kwargs.items(): | |
setattr(self, name, value) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment