Last active
December 11, 2021 09:44
-
-
Save lucianmarin/cabb7a3ac7c2f98f6974ac70b180abd3 to your computer and use it in GitHub Desktop.
Alternative to namedtuple and dataclass in Python
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
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