Skip to content

Instantly share code, notes, and snippets.

@laygond
Last active January 17, 2023 15:15
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 laygond/936c7acd54fc100fcc51e7e7e28e280e to your computer and use it in GitHub Desktop.
Save laygond/936c7acd54fc100fcc51e7e7e28e280e to your computer and use it in GitHub Desktop.
Overload Print function to pretty print Dictionaries
import json
def print_decorator(func):
"""
Overload Print function to pretty print Dictionaries
"""
def wrapped_func(*args,**kwargs):
if isinstance(*args, dict):
return func(json.dumps(*args, sort_keys=True, indent=2, default=str))
else:
return func(*args,**kwargs)
return wrapped_func
print = print_decorator(print)
# Now use print() as usual
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment