title: Reading a two-column file into Python
body: <p>Suppose I have a data file called "test.dat" which is of the form "1 2 \n 3 4 \n 5 6".</p>
  
  <p>If I run the following code, I get two arrays with the numbers in them:</p>
  
  <pre><code>import csv
  from numpy           import *
  f2 = open('test.dat', 'r') 
  lines = f2.readlines()
  x = []
  y = [] 
  for line in lines:
      p = line.split()
      x.append(float(p[0]))
      y.append(float(p[1]))
  f2.close() 
  
  print x
  print y
  </code></pre>
  
  <p>However, I tried writing a function of the form</p>
  
  <pre><code>def Read_Two_Column_File(file_name):
      data  = open(file_name, 'r')
      lines = data.readlines()
      x = []
      y = []
      for line in lines:
          p = line.split()
          x.append(float(p[0]))
          y.append(float(p[1]))
      data.close()
      return x, y
  
  x, y = Read_Two_Column_File('test.dat')
  
  print x 
  print y
  </code></pre>
  
  <p>but this only returns the two last numbers. What is going wrong here?</p>