title: Import functions in Python
body: <p>How can i import functions that make use of a variable defined in the current file?</p>
  
  <p><strong>main.py</strong></p>
  
  <pre><code>from functions import a
  
  x = 1
  
  print(a())
  </code></pre>
  
  <p><strong>functions.py</strong></p>
  
  <pre><code>def a():
      return x
  </code></pre>
  
  <p><strong>Error Message</strong></p>
  
  <pre><code>Traceback (most recent call last):
    File "c:\Users\Test\.vscode\extensions\ms-python.python-2019.4.11987\pythonFiles\ptvsd_launcher.py", line 43, in &lt;module&gt;
      main(ptvsdArgs)
    File "c:\Users\Test\.vscode\extensions\ms-python.python-2019.4.11987\pythonFiles\lib\python\ptvsd\__main__.py", line 410, in main
      run()
    File "c:\Users\Test\.vscode\extensions\ms-python.python-2019.4.11987\pythonFiles\lib\python\ptvsd\__main__.py", line 291, in run_file
      runpy.run_path(target, run_name='__main__')
    File "C:\Users\Test\AppData\Local\Programs\Python\Python37\lib\runpy.py", line 263, in run_path
      pkg_name=pkg_name, script_name=fname)
    File "C:\Users\Test\AppData\Local\Programs\Python\Python37\lib\runpy.py", line 96, in _run_module_code
      mod_name, mod_spec, pkg_name, script_name)
    File "C:\Users\Test\AppData\Local\Programs\Python\Python37\lib\runpy.py", line 85, in _run_code
      exec(code, run_globals)
    File "c:\Users\Test\Google Drive\Dev\Test\main.py", line 5, in &lt;module&gt;
      print(a())
    File "c:\Users\Test\Google Drive\Dev\Test\functions.py", line 2, in a
      return x
  NameError: name 'x' is not defined
  </code></pre>