title: Using variables inside a function in another python file
body: <p>i cant seem to make this work.</p>
  
  <p>I have 2 python files, lets say a.py and b.py</p>
  
  <p><strong>in a.py is this:</strong></p>
  
  <pre><code>def foo():
      global name
      name = "foo"
      import b
      b.bar()
  
  if __name__ == "__main__":
      foo()
  </code></pre>
  
  <p><strong>in b.py this:</strong></p>
  
  <pre><code>import a
  
  def bar():
      name = a.name
      print(name)
  </code></pre>
  
  <p>I have three different question in relation to this code:</p>
  
  <ol>
  <li>Why do i get the error: <code>AttributeError: 'module' object has no attribute 'name'</code>
  I know for certain that b.py cant access the variable defined in the function in b.py but how do i solve this?</li>
  <li>does global in this case changes anything? if not, why?</li>
  <li>i tried doing <code>name = a.foo.name</code> instead of <code>name = a.name</code> but this doesnt do the trick either and gives me: <code>AttributeError: 'function' object has no attribute 'name'</code>,
  is this even practicable in any case and what did i do wrong?</li>
  </ol>
  
  <p>Thanks for taking the time and sorry if this seems obvious to some of you, i'am still getting into this.</p>