Last active
January 17, 2023 15:15
-
-
Save laygond/936c7acd54fc100fcc51e7e7e28e280e to your computer and use it in GitHub Desktop.
Overload Print function to pretty print Dictionaries
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
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