title: Python Why use open(filename) twice in this code?
body: <p>Here's a piece of code from Machine Learning in Action Chap2. 
  The goal is to transfer a file to matix. What I dont understand is why should I use fr=open(filename) twice?</p>
  
  <p>When I delete the second open(filename), the code just return blank matrix. And I cant figure it why.</p>
  
  <p>Thanks a lot for taking time!</p>
  
  <pre><code>def file2matrix(filename):
      fr = open(filename)
      numberOfLines = len(fr.readlines())        
      returnMat = zeros((numberOfLines,3))       
      classLabelVector = []                       
      fr = open(filename)
      index = 0
      for line in fr.readlines():
          line = line.strip()
          listFromLine = line.split('\t')
          returnMat[index,:] = listFromLine[0:3]
          classLabelVector.append(int(listFromLine[-1]))
          index += 1
      return returnMat,classLabelVector
  </code></pre>