[portland] New data, old script: new problem
rshepard at appl-ecosys.com
Wed Mar 23 01:57:12 CET 2011
Me again. Python is telling me that there are 13 items in the row count in
addition to row where there should be only 12. I don't see the error and
there is no blank space at the end of the row.
I've attached the script (datacon.py) that worked before, and here's a
very short data set that throws the error:
Traceback (most recent call last):
File "./datacon.py", line 32, in <module>
if row[i] != '':
IndexError: list index out of range
I've printed stubs and found that the list index is looking for one too
many items, but I don't see where it's getting the incorrect count. Please
point out what's incompatible with the script or data file.
-------------- next part --------------
filename = sys.argv
infile = open(filename, 'r')
print "Can't open ", filename,"!"
indata = csv.reader(infile, delimiter=':')
loc = indata.next()
sampdate = indata.next()
# check for mis-match in number of columns
assert len(loc) == len(sampdate)
outfile = open('out.csv', 'w')
outdata = csv.writer(outfile, delimiter = ':', lineterminator = '\n')
# The next rows are our parameters.
for row in indata:
# iterate through each column for the particular locations
for i, location in enumerate(loc):
# ignore the first column, which contains the parameter name
if i == 0:
# Write the location, the date for this column, the parameter name
# (which is the first column in this row), and the value.
if row[i] != '':
outdata.writerow([location, sampdate[i], row, float(row[i])])
row[i] = ''
outdata.writerow([location, sampdate[i], row])
More information about the Portland