Skip to content

Instantly share code, notes, and snippets.

@ericleong
Created April 18, 2014 17:31
Show Gist options
  • Save ericleong/11055297 to your computer and use it in GitHub Desktop.
Save ericleong/11055297 to your computer and use it in GitHub Desktop.
Map Constructor Keyword Arguments to Object Fields
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