-
Notifications
You must be signed in to change notification settings - Fork 0
/
printme.py
32 lines (27 loc) · 930 Bytes
/
printme.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
maintenance version of 'print' function
will print the name, the content and the class of the variable fed into printme
also provides colored output presets
"""
from colorama import Back, Fore
import inspect
clrs = Fore.RESET + Back.RESET
magenta = clrs + Fore.LIGHTMAGENTA_EX
blue = clrs + Fore.BLUE
green = clrs + Fore.LIGHTGREEN_EX
grey = clrs + Fore.WHITE
yellow = clrs + Fore.YELLOW
turk = clrs + Fore.LIGHTCYAN_EX
red = clrs + Fore.RED
def printme(vrname): # prints the name, the content and the class of the variable fed into printme
for var_name, var_value in inspect.currentframe().f_back.f_locals.items():
if var_value is vrname:
vartitle = var_name
break
else:
vartitle = "<unknown>"
vrtype = str(type(vrname))
vrname = str(vrname)
print(magenta + vartitle, ": ", green + vrname, turk + vrtype + clrs)