Get the name of a python variable
Question: 
    def f(s)
      print <name of s> = s
    

I wish to output "hello=10" for `f(hello)`, given that the variable hello has
value 10.

The problem is how to get the variable name of the variable, i.e., `<name of
s>`?

This is for debugging purpose. Say given a new statement `s=2`

`f(s)` before the new statement will print `s=0` if `s` is initially 0, `f(s)`
after the new statement will print `s=2`.

I can easily write:

    
    
    def f(name,value)
       print "%s=%s"%(name,str(value))
    

and use it as `f("s",s)`, but that would need me to input two arguments, which
is more cumbersome.


Answer: I am not sure if it is actually worth it, but using the information from
frames for simple function calls with positional arguments you can do
something like this:

    
    
    import inspect
    
    def hello(s1, s2, s3, s4):
        args = inspect.getargspec(hello).args
        line = inspect.getouterframes(inspect.currentframe())[1][4][0]
        actual_args = map(str.strip, line[line.index('(')+1: line.index(')')].split(','))
        for x, y in zip(args, actual_args):
            print "value of {} is {}".format(y, locals()[x])
    
    a, b, c, d = 1, 2, 3, 4
    hello(a, b, c, d)
    

### output:

    
    
    value of a is 1
    value of b is 2
    value of c is 3
    value of d is 4
    

