I am looking for a way to quickly print the name and value of a variable when quickly developing / debugging a small Python script in a Unix / ssh command line session.
This seems like a very common requirement, and it seems wasteful (on key presses and time / energy) to duplicate the variable_name name on every line that prints or writes its value. that is, not
print 'my_variable_name:', my_variable_name
I want to be able to do the following for str , int , list , dict :
log(my_variable_name) log(i) log(my_string) log(my_list)
and get the following output:
my_variable_name:some string i:10 my_string:a string of words my_list:[1, 2, 3]
Ideally, the output also writes the name of the function.
I have seen some solutions trying to use locals , globals , frames, etc., but I have not yet seen something that works for integers, strings, lists, and also works inside functions.
Thanks!
source share