Created
March 19, 2015 18:59
-
-
Save jsbueno/e56f56c73200be88b5fb to your computer and use it in GitHub Desktop.
"simpleclass" - namedtuple like factory for mutable objects
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
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