title: How to find the name of a variable that was passed to a function?
body: <p>In C/C++, I have often found it useful while debugging to define a macro, say <code>ECHO(x)</code>, that prints out the variable name and its value (i.e. <code>ECHO(variable)</code> might print <code>variable 7</code>).  You can get the variable name in a macro using the 'stringification' operator <code>#</code> as described <a href="http://gcc.gnu.org/onlinedocs/cpp/Stringification.html" rel="nofollow">here</a>.  Is there a way of doing this in Python?</p>
  
  <p>In other words, I would like a function</p>
  
  <pre><code>def echo(x):
      #magic goes here
  </code></pre>
  
  <p>which, if called as <code>foo=7; echo(foo)</code> (or <code>foo=7; echo('foo')</code>, maybe), would print out <code>foo 7</code>.  I realise it is trivial to do this if I pass both the variable and its name to the function, but I use functions like this a lot while debugging, and the repetition always ends up irritating me.</p>