Skip to content

Instantly share code, notes, and snippets.

@terabyte
Created December 7, 2021 00:38
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save terabyte/8b961c29eab7fd155ddbe115d7941326 to your computer and use it in GitHub Desktop.
Save terabyte/8b961c29eab7fd155ddbe115d7941326 to your computer and use it in GitHub Desktop.
def default_serialize_func(o):
"""
Use like this: logging.debug(f"print this object: {json.dumps(myobject, indent=4, sort_keys=True, default=default_serialize_func)}")
"""
if hasattr(o, '__dict__'):
return o.__dict__
return f"<could not serialize {o.__class__}>"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment