title: NameError: global name 'name' is not defined (while it is defined.)
body: <p>I'm new to python and now making some program with it.
  <p>I have two files, which are <code>trans.py</code> and <code>main.py</code>.
  <p>In <code>trans.py</code>,</p>
  
  <pre><code>from math import *
  from numpy import *
  
  
  def matrix_T(d): 
      global mat_A, mat_B, mat_C, mat_D   
      temp_A, temp_B, temp_C, temp_D = mat_A, mat_B, mat_C, mat_D
      mat_A = 1.0*temp_A + d*temp_C     
      mat_B = 1.0*temp_B + d*temp_D
      mat_C = 1.0*temp_C
      mat_D = 1.0*temp_D
  </code></pre>
  
  <p>In <code>main.py</code>,</p>
  
  <pre><code>from trans import *
  
  global mat_A, mat_B, mat_C, mat_D
  mat_A = 1.0
  mat_B = 0.0
  mat_C = 0.0
  mat_D = 1.0
  
  print(mat_A, mat_B, mat_C, mat_D)
  
  matrix_T(0.0)
  
  print(mat_A, mat_B, mat_C, mat_D)
  </code></pre>
  
  <p>and when I run <code>main.py</code>, of course get this error.</p>
  
  <pre><code>Traceback (most recent call last):
    File "main.py", line 11, in &lt;module&gt;
      matrix_T(0.0)
    File "trans.py", line 6, in matrix_T
      temp_A, temp_B, temp_C, temp_D = mat_A. mat_B, mat_C, mat_D
  NameError: global name 'mat_A' is not defined
  </code></pre>
  
  <p>Since I thought I defined global variable mat_A to mat_D, how could I avoid this problem?
  <p> Thanks in advance.</p>