Created
April 18, 2014 18:41
-
-
Save ericleong/11058494 to your computer and use it in GitHub Desktop.
Map Constructor 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, 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