Skip to content

Instantly share code, notes, and snippets.

@glombard
Created December 9, 2014 19:57
Show Gist options
  • Star 8 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save glombard/48faa865264548dd71a8 to your computer and use it in GitHub Desktop.
Save glombard/48faa865264548dd71a8 to your computer and use it in GitHub Desktop.
Python anonymous object
# 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