title: python: Print variable name of args received from another file
body: <p>I need to print variable names, so I did:</p>
  
  <pre><code>def get_variable_name(x):
      local_matches = [k for k, v in locals().items() if v is x]
      global_matches = [k for k, v in globals().items() if v is x]
  
      print(local_matches, global_matches)
      return global_matches[0]
  
  a = 5
  print(get_variable_name(a))
  
  # output
  # (['x'], ['a'])
  # a
  </code></pre>
  
  <p>That's now perfect, but now I need to use this <code>get_variable_name</code> function in many places in my project. So I moved this function to <code>utils.py</code>, and we can now import it and use it like:</p>
  
  <pre><code>from scripts.utils import get_variable_name
  a = 5
  print(get_variable_name(a))
  
  # output
  # (['x'],[])
  # ! can't access index 0 exception
  # ! since the list is empty
  </code></pre>
  
  <p>Clearly, in the former, a is found in the global var stack and in the latter it's not, since when it's inside of <code>utils.py</code> executing this functions, <code>globals()</code> does not contain <code>a</code>, since it is not declared in the global scope (of the file).</p>
  
  <p>So we got <code>locals().items()</code> to give local vars, and <code>globals().items()</code> for global vars, <strong>How do I access inter-file scope variable stack?</strong></p>
  
  <hr>
  
  <p>UPDATE:</p>
  
  <p>In another SO <a href="https://stackoverflow.com/q/3400525/3125070">question</a>, mentioned in the comments, they are dealing with variables defined in the global scope in <code>file1</code> and this will not be available in <code>file2</code> because, <code>file1</code> imports  only modules of <code>file2</code>.</p>
  
  <p>But here, I am sending these variables to <code>file2</code>, and obviously, values of which it<code>file2</code> has access to, but how do I access the names of the arguments passed? (And I don't see a security or dependency flaw associated with this, as it already has access to the variable, I just want their names)</p>