Last active
January 10, 2023 20:30
-
-
Save Bktero/c85e08fc17d06bff81ba081524167087 to your computer and use it in GitHub Desktop.
[Python] Generic __str__ method for a Python class
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 __str__(self): | |
elements = [] | |
for key, value in self.__dict__.items(): | |
elements.append("{key}='{value}'".format(key=key, value=value)) | |
return ', '.join(elements) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment