title: accessing namespace which called a function using builtin dir()
body: <p>i am having a problem with scope. i would like to have a function  operate on the result of the builtin function <code>dir()</code>. so, as a simple example, i want to </p>
  
  <pre><code>&gt;&gt;&gt; print (dir())
  &gt;&gt;&gt;  .... bunch of stuff ...
  </code></pre>
  
  <p>but, i want define a function which operates on this results of dir(). however, if try this like so</p>
  
  <pre><code>&gt;&gt;&gt; def print_dir(dummy_var=None):
          print dir()
  &gt;&gt;&gt; print_dir()
  &gt;&gt;&gt; ['dummy_var']
  </code></pre>
  
  <p>i cant access the namespace of what called <code>print_dir</code> which i understand is a scope thing and makes sense, but is there a way to access the namespace from which a function is called? or do i have to pass the result of dir() to the function? like. </p>
  
  <pre><code>&gt;&gt;&gt; act_on_namespace(dir())
  </code></pre>
  
  <p>the specific goal in mind is something like this, </p>
  
  <pre><code>def act_on_namespace()
      for k in dir():
          try:
              print(eval(k).__module__)
          except:
              pass
  </code></pre>