title: Read TXT file line by line - Python
body: <p>How can I tell python to read a txt list line by line?
  I'm using .readlines() which doesn't seem to be working. </p>
  
  <pre><code>import itertools
  import string
  def guess_password(real):
      inFile = open('test.txt', 'r')
      chars = inFile.readlines()
      attempts = 0
      for password_length in range(1, 9):
          for guess in itertools.product(chars, repeat=password_length):
              attempts += 1
              guess = ''.join(guess)
              if guess == real:
                  return input('password is {}. found in {} guesses.'.format(guess, attempts))
          print(guess, attempts)
  
  print(guess_password(input("Enter password")))
  </code></pre>
  
  <p>The test.txt file looks like:</p>
  
  <pre><code>1:password1
  2:password2
  3:password3
  4:password4
  </code></pre>
  
  <p>currently the program only works with the last password on the list (password4)
  if any other password is entered it will run past all the passwords on the list and return "none".</p>
  
  <p>So I assume I should be telling python to test each line one at a time?</p>
  
  <p>PS. the "return input()" is an input so that the dialog box doesn't close automatically, there's nothing to be inputted.</p>