log a variable name and value
Question: I am looking for a way to quickly print a variable name and value while
rapidly developing/debugging a small python script on a unix command line/ssh
session.

It seems like a very common requirement and it seems wasteful (on keystrokes
and time/energy) to duplicate the variable_names on every line which prints or
logs its value. i.e. rather than

    
    
    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 would also log the function name

I have seen some solutions attempting to use locals, globals, frames etc., But
I have not yet seen something that works for ints, strings, lists, and works
inside functions too.

Thanks


Answer: If the tool you need is only for developing and debugging, there's a useful
package calle [q](https://github.com/zestyping/q).

It has been submitted to pypi, it can be installed with `pip install q` or
`easy_install q`.

    
    
    import q; q(foo)
    
    # use @q to trace a function's arguments and return value
    @q
    def bar():
       ...
    
    # to start an interactive console at any point in your code:
    q.d()
    

The results are output to the file /tmp/q(or any customized paths) by
default,so they won't be mixed with stdout and normal logs. You can check the
output with `tail -f /tmp/q`. The output is highlighted with different colors.

The author introduced his library in a lightning talk of PyconUS 2013. The
video is
[here](http://www.youtube.com/watch?feature=player_embedded&v=OL3De8BAhME),
begins at 25:15.

