title: python read file, print part of line that begins with a specific string
body: <p>I have a text file which contains the following</p>
  
  <pre><code>steve:789852:1
  sean:1234:1
  </code></pre>
  
  <p>I want to read the file and is the input from a user matches the first name then print out the middle number.
  I can do this for one line but not for the rest I keep getting </p>
  
  <p><code>IndexError: list index out of range</code></p>
  
  <p>I have tried a for loop and a while loop. The code I am using is below. any help please</p>
  
  <pre><code>x = 0
  username = input('enter user name ')
  file = open('user_details.txt', 'r')
  count = len(open('user_details.txt').readlines())
  while x &lt; count:
      print(x)
      userFile = file.read().split('\n')[x]
      userArray = userFile.split(':')
      if (userArray[0] == username):
          print('password = '+userArray[1])
      x = x+1
  </code></pre>