title: NameError: global name 'myLogFile' is not defined
body: <p>I have two functions, I have placed one of the functions into a seperate .py so I can import it, but I get an error when I try to run the script.</p>
  
  <p>The function that I placed into the separate .py is:</p>
  
  <pre><code>def output_messaging(message):
      global myEmailText
      myLogFile.write(message)
      myEmailText = myEmailText + message
      print message
  </code></pre>
  
  <p>The script that I run has the following code:</p>
  
  <pre><code>def finish_process(errors):
      global myLogFile
      myLogFile.close()
      if errors == 0:
          myEmailHeader = "Subject: **"
      elif errors == 1:
          myEmailHeader = "Subject: **"
      else:
          myEmailDestination.append("**") 
          #myEmailHeader = "Subject: **"
      server = smtplib.SMTP(myServer) #email data log to nominated individuals
      server.sendmail(myEmailSender, myEmailDestination, myEmailHeader + "\n" + myEmailText)
      server.quit()
  </code></pre>
  
  <p>When I run the script i get the following error.</p>
  
  <pre><code>NameError: global name 'myLogFile' is not defined
  </code></pre>
  
  <p>myLogFile is declared lower down in the code (which is the location of the log file), but I'm slightly confused.</p>
  
  <p>Thanks</p>