I often need to print variables for debugging purposes, and I found out that it helps a lot to also know what those variables are. So I would like to have a function that does sort of the following:
from __future__ import print_function
def get_variable_name(my_variable):
... ?
def print_with_variable_name(my_variable):
print (get_variable_name(my_variable), ': ', my_variable)
a = 30
print_with_variable_name(a);
Expected output:
a: 30
I found some partial solutions to the problem where I could do that only in the function where the function was defined by the name a, otherwise it would print:
my_variable: 30
Is there any elegant solution to the problem where I can just write a module with this new print function and import it wherever I like?