Skip to content

Instantly share code, notes, and snippets.

@jsbueno
Created March 19, 2015 18:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jsbueno/e56f56c73200be88b5fb to your computer and use it in GitHub Desktop.
Save jsbueno/e56f56c73200be88b5fb to your computer and use it in GitHub Desktop.
"simpleclass" - namedtuple like factory for mutable objects
def simpleclass(name, attributes, **kw):
if isinstance(attributes, str):
attributes = attributes.split()
def __init__(self, *args, **kw):
attrs = dict(zip(self.__slots__, args))
attrs.update(kw)
for item in attrs.items():
setattr(self, *item)
return type(name, (object,), dict(__init__=__init__, __slots__= attributes))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment