Python: Spaced Data-to-CSV Data
<p>I think there is a simple Python solution, but I cannot seem to get there in an elegant manner.  </p>

<p>I am basically trying to take 3-columns of spaced data, truncate several rows off the top, and then re-store the 3-columns of data as a CSV file.  Essentially separating the column fields by a single comma.</p>

<p>Th column field formats will be: integer, float, float</p>

<p>My attempt is shown below.</p>

<p>Thanks much for the help.</p>

<hr>

<pre><code>import csv
""" assume list1.txt data file looks like this:

1    1.12      3.1456756
2    1.123     3.145675
3    1.1234    3.14567
4    1.12345   3.1456
5    1.1234    3.145
6    1.123     3.1456
7    1.12      3.14567
8    1.1       3.145675
9    1.12      3.1456756
10   1.123     3.14567568

"""
# read the data file in as a list
fin = open( 'list1.txt', "r" )
data_list = fin.readlines()
fin.close()

# REPRODUCE THE LINES 1 THRU 5 OF THE ORIGINAL FILE
print data_list[:5]
print '-'*60

# remove LINES 1 THRU 5 FROM THE READ IN DATA LIST
del data_list[:5]

# PRINT FIRST 5 LINES OF THE NEW DATA LIST
print data_list[:5]

# write the changed data (list) to a file
fout = open("list2.txt", "w")
fout.writelines(data_list)
fout.close()

# write the changed data (list) to a CSV.file
csv_in = csv.reader(open('list2.txt', 'rb'), delimiter=' ')
csv_out = csv.writer(open('list3.csv', 'wb'), delimiter=',')
for line in csv_in:
    csv_out.writerow(line)
</code></pre>
