Created
November 20, 2023 10:07
-
-
Save psenger/505125efad5b889de6ea39cc018844a5 to your computer and use it in GitHub Desktop.
[Adding a toString to a class] #Python
This file contains hidden or 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 auto_str(cls): | |
| def __str__(self): | |
| return '%s(%s)' % ( | |
| type(self).__name__, | |
| ', '.join('%s=%s' % item for item in vars(self).items()) | |
| ) | |
| cls.__str__ = __str__ | |
| return cls | |
| # @auto_str | |
| # class Tag: | |
| # | |
| # def __init__(self, name, creator, organization, id=None): | |
| # if id is None: | |
| # self.id = uuid.uuid4() | |
| # else: | |
| # self.id = id | |
| # self.name = name | |
| # self.creator = creator | |
| # self.organization = organization | |
| # self.created_on = get_utc_datetime() | |
| # self.modified_on = get_utc_datetime() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment