title: Python: How can I use variable from main file in module?
body: <p>I have 2 files main.py and irc.py.<br>
  main.py</p>
  
  <pre><code>import irc
  var = 1
  func()
  </code></pre>
  
  <p>irc.py</p>
  
  <pre><code>def func():
      print var
  </code></pre>
  
  <p>When I try to run main.py I'm getting this error</p>
  
  <blockquote>
    <p>NameError: global name 'var' is not defined</p>
  </blockquote>
  
  <p>How to make it work?</p>
  
  <p>@Edit<br>
  I thought there is a better solution but unfortunately the only one i found is to make another file and import it to both files<br>
  main.py  </p>
  
  <pre><code>import irc
  import another
  another.var = 1
  irc.func()
  </code></pre>
  
  <p>irc.py</p>
  
  <pre><code>import another
  def func():
      print another.var
  </code></pre>
  
  <p>another.py</p>
  
  <pre><code>var = 0
  </code></pre>