Skip to content

Instantly share code, notes, and snippets.

@matyasfodor
Last active July 16, 2017 21:31
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 matyasfodor/16f1fb62ab7a8b6f799ad048bd4ca452 to your computer and use it in GitHub Desktop.
Save matyasfodor/16f1fb62ab7a8b6f799ad048bd4ca452 to your computer and use it in GitHub Desktop.
def record_factory(cls_name, field_names):
# ...
def _asdict(self):
return {k: getattr(self, k) for k in self.__slots__}
cls_attrs = dict(__slots__ = field_names,
__init__ = __init__,
__iter__ = __iter__,
__repr__ = __repr__,
__hash__ = __hash__,
__eq__ = __eq__,
_asdict = _asdict)
return type(cls_name, (object,), cls_attrs)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment