title: local vs global variables Python
body: <p>I am new to programming and am wondering if this is possible.  I am trying to create a password protected script, where the password is entered once and then required to progress the script the next time the script is opened.  I am storing and encrypting the password in a file, and then checking to see if the file exists the next time the script is opened.  The problem I am running into is checking to see if the passwords match, since the original password is in a function as a local variable.  </p>
  
  <pre><code>def createFile():
      pw = input('Enter Password: ')
      pw2 = input('ReType Password: ')
      if pw == pw2:        
          newPw = encrypt(pw, 10)  #encodes the string with a key in a seperate encrypt function
          pwFile = open('PW.txt', 'a')
          pwFile.write(newPw)
          pwFile.close()
      else:
          print('The passwords do not match')
          createFile()
  
  
  if os.path.isfile('PW.txt'):
      print('File exists')
      pwCheck = input('What is the password? ')
      #I can not check pwCheck == pw since pw is a local var.
  
      #progression of script here
  else:
      createFile()
  </code></pre>
  
  <p>I know that it is considered bad for to make a local variable global.  Is there a way to restructure what I have so far to make this work?  As I wrote this, I think I may have came up with a possible solution but I do not have time to test it now.  Do I run the same encrypt function with the same key for pwCheck and then check if it is == to the first line of PW.txt?  Is that correct and/or are there other solutions?</p>
  
  <p>Thank you.</p>
  
  <p>Using Windows, Python 3.4</p>