title: Global variables in Python to share variable across files
body: <p>I have a Python script that gets a command line argument, and then it is stored as a global variable within the script:</p>
  
  <pre><code>global chain
  chain = sys.argv[1]
  </code></pre>
  
  <p>The script then imports a couple of other files, each containing another function. I am trying to carry the value of this variable to the other functions as well, by doing the following:</p>
  
  <pre><code>def func():
      global chain
      #do stuff
  </code></pre>
  
  <p>which is contained in another file than the original script.</p>
  
  <p>When I run the script, I get </p>
  
  <pre><code>NameError: global name 'chain' is not defined
  </code></pre>
  
  <p>What am I missing?</p>