Last active
February 6, 2020 23:51
-
-
Save wcarhart/cf3944f3a62415406f8bd92c427173e5 to your computer and use it in GitHub Desktop.
Code sample from blog post: https://www.willcarh.art/blog/the-power-of-introspection-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
def jsonize(self): | |
variables = [var for var in dir(self) if not var.startswith(('_', '__')) and not callable(getattr(self, var))] | |
return "{" + ",".join([f"\"{var}\": \"{getattr(self, var)}\"" for var in variables]) + "}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment