title: Select columns from a data file and place it in another file, with python
body: <p>I'm new on python and I have a problem to solve.
  I have a data file in columns and separated from blank spaces. I would just select some columns and write them to another text file (.txt or .dat doesn't matter), and I would like to do so so I can use this code for other files with different columns.
  This is a sketch of my file:</p>
  
  <pre><code>        1     2332     2332 1.851E+14 1.851E+14 1377.93     0 0.000E+00  281.0788  680.7861  121.3181   588.19  -110.23  -116.67  774.44 -7.3979E+19       354169084    0.0162
          2     1528     1528 1.213E+14 1.213E+14 1197.00     0 0.000E+00  189.8768  285.5306   70.2188  -251.45   240.42  -793.13  623.65 -3.7264E+19       168917161    0.0124
          3     3247     3247 2.578E+14 2.578E+14 1538.90     0 0.000E+00  669.2193  332.7487  340.3935   -76.77   145.31   -70.35  778.94 -1.3707E+20       710525468    0.0252
  </code></pre>
  
  <p>I tried this:</p>
  
  <pre><code>import csv
  csv_in = csv.reader(open('complete_lowtry.dat', 'rb'), delimiter='\t')
  csv_out = csv.writer(open('spam.dat', 'w'), delimiter=',')
  
  for line in csv_in:
  csv_out.writerow(line[8], line[9], line[10])
  </code></pre>
  
  <p>and another code:</p>
  
  <pre><code>import csv
  
  csv_out = csv.writer(open('out.csv', 'w'), delimiter=',')
  
  f = open('myfile.txt')
  for line in f:
     vals = line.split('\t')
     csv_out.writerow(vals[8], vals[9], vals[10])
  f.close()
  </code></pre>
  
  <p>that i found on the site. I want to take the columns 8,9 and 10, but in both cases I find the error:</p>
  
  <pre><code>csv_out.writerow(line[8], line[9], line[10])
  IndexError: list index out of range
  </code></pre>
  
  <p>Can someone help me, please?
  I'm a mac user and I use python 2.7.</p>