Adding a column in a tab delimited txt file
Harald Massa
cpl.19.ghum at spamgourmet.com
Fri Aug 22 16:30:56 EDT 2003
... 20 columns, now I need to add another column of zero at the 4th
column
position and a column of zero at the 9th column position. What is the
import csv
reader = csv.reader(open("sample.csv"))
writer = csv.writer(open("sample2.csv","w")
for data in reader:
writer.writerow([data[:4]+[0]+data[4:7]+[0]+data[7:])
http://online.effbot.org/2003_08_01_archive.htm#librarybook-csv-module
Maybe optimization with the list concatenation is possible. But first
test, if it is not fast enough.
(csv is included with python 2.3, is available seperately in the internet
for 2.2 also)
Harald
More information about the Python-list
mailing list