Last active
July 5, 2023 14:27
-
-
Save Dj0ulo/d7ed164e2ec0984a79517fe7357ed2e4 to your computer and use it in GitHub Desktop.
pdb print in color
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 _pc(dictionary=locals(), ignore=['__builtins__'], indent=0): | |
try: | |
keys = dictionary._fields | |
except: | |
try: | |
keys = dictionary.keys() | |
except: | |
keys = dictionary.__dict__.keys() | |
for key in keys: | |
if key in ignore: | |
continue | |
try: | |
value = dictionary[key] | |
except: | |
print('\t' * indent + '\033[95m' + str(key) + '\033[0m' + ': \033[91mAccess Error\033[0m') | |
continue | |
if isinstance(value, dict): | |
print('\t' * indent + '\033[95m' + str(key) + '\033[0m' + ': {') | |
_pc(value, ignore, indent + 1) | |
print('\t' * indent + '}') | |
else: | |
value_str = '\033[93m\'' + str(value) + '\'\033[0m' if isinstance(value, str) else '\033[96m' + str(value) + '\033[0m' | |
print('\t' * indent + '\033[95m' + str(key) + '\033[0m' + ': ' + value_str) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment