Created
December 9, 2014 19:57
-
-
Save glombard/48faa865264548dd71a8 to your computer and use it in GitHub Desktop.
Python anonymous object
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
# Sometimes it's handy to create small anonymous objects instead of explicitly defining a class for it, especially while prototyping. | |
def new(name, data): | |
return type(name, (object,), data) | |
person = new('Person', { 'name': 'Joe', 'age': 30 }) | |
print(person.name) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment