Skip to content

Instantly share code, notes, and snippets.

@Dj0ulo
Last active July 5, 2023 14:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Dj0ulo/d7ed164e2ec0984a79517fe7357ed2e4 to your computer and use it in GitHub Desktop.
Save Dj0ulo/d7ed164e2ec0984a79517fe7357ed2e4 to your computer and use it in GitHub Desktop.
pdb print in color
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