Skip to content

Instantly share code, notes, and snippets.

@lucianmarin
Last active December 11, 2021 09:44
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 lucianmarin/cabb7a3ac7c2f98f6974ac70b180abd3 to your computer and use it in GitHub Desktop.
Save lucianmarin/cabb7a3ac7c2f98f6974ac70b180abd3 to your computer and use it in GitHub Desktop.
Alternative to namedtuple and dataclass in Python
class Metaclass:
def asdict(self):
return self.__dict__
def astuple(self):
return tuple(self.__dict__.values())
def fields(self):
return list(self.__dict__.keys())
class User(Metaclass):
def __init__(self, name="", password="secret", related=None):
self.name = name
self.password = password
self.related = related
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment