Skip to content

Instantly share code, notes, and snippets.

@ericleong
Created April 18, 2014 18:41
Show Gist options
  • Save ericleong/11058494 to your computer and use it in GitHub Desktop.
Save ericleong/11058494 to your computer and use it in GitHub Desktop.
Map Constructor Arguments to Object Fields
class Thing:
def __init__(self, a=1, b='two'):
# Iterate through local variables and assign as fields
for name, value in locals().items():
if name != 'self':
setattr(self, name, value)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment