title: inspect.getargvalues() throws exception "AttributeError: 'tuple' object has no attribute 'f_code'"
body: <p>I'm trying to use Python's <code>inspect</code> module (in Python 2) to show information about the function that called the current function, including its arguments.</p>
  
  <p>Here's a simple test program:</p>
  
  <pre><code>import inspect
  
  def caller_args():
      frame = inspect.currentframe()
      outer_frames = inspect.getouterframes(frame)
      caller_frame = outer_frames[1]
      return inspect.getargvalues(caller_frame)
  
  def fun_a(arg1):
      print caller_args()
  
  def fun_b():
      fun_a('foo')
  
  if __name__ == '__main__':
      fun_b()
  </code></pre>
  
  <p>And this happens when I run it:</p>
  
  <pre><code>$ python getargvalues_test.py
  Traceback (most recent call last):
    File "getargvalues_test.py", line 16, in &lt;module&gt;
      fun_b()
    File "getargvalues_test.py", line 13, in fun_b
      fun_a('foo')
    File "getargvalues_test.py", line 10, in fun_a
      print caller_args()
    File "getargvalues_test.py", line 7, in caller_args
      return inspect.getargvalues(caller_frame)
    File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/inspect.py", line 829, in getargvalues
      args, varargs, varkw = getargs(frame.f_code)
  AttributeError: 'tuple' object has no attribute 'f_code'
  </code></pre>
  
  <p>I've googled that AttributeError exception, but with no luck. What am I doing wrong?</p>
  
  <p>(I've since found the problem, so I'm asking-and-answering this here so anyone who has this problem in future will find the answer here.)</p>