I think the problem is with how you&#39;re referencing the row from indata.  I&#39;m not quite sure what you&#39;re trying to do with i and j.  I&#39;d get rid of i and j and replace the for loop with the following:<div><br>
</div><div>for row in indata:</div><div>    for parm, rowval in zip(parmlist,row[1:]): </div><div>        outdata.writerow([loc, row[0], parm, rowval])<br><div><br></div><div>(I didn&#39;t try the code out, so there may be a typo or some other error.)</div>
<div><br></div><div>Ryan</div><div><br></div><div><br></div><div><br><div class="gmail_quote">On Thu, Aug 11, 2011 at 2:31 PM, Rich Shepard <span dir="ltr">&lt;<a href="mailto:rshepard@appl-ecosys.com">rshepard@appl-ecosys.com</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">  Once again it&#39;s been too long since I&#39;ve written a script; every time I<br>
mean to finish a model I&#39;ve been writing a more critical business need has<br>
pushed the coding back.<br>
<br>
  I&#39;m now faced with translating a couple of dozen spreadsheets (saved as<br>
.csv files) into the proper format for insertion into a database table. My<br>
brain refuses to get the row indexing correct.<br>
<br>
  Here is the first few rows of a typical file:<br>
<br>
CVS<br>
Arsenic:Zinc:Nitrate Nitrogen:pH:Chloride:Sulfate:<u></u>Total Dissolved Solids<br>
1993-11-22:0.008:0.014:0.021:<u></u>7.560:2.060:39.3:293.0<br>
<br>
  I want an output file that looks like<br>
<br>
CVS|1993-11-22|Arsenic|0.008<br>
CVS|1993-11-22|Zinc|0.014<br>
etc.<br>
<br>
  The mal-functioning script is:<br>
-------------------------<br>
#!/usr/bin/env python<br>
<br>
import sys,csv<br>
<br>
filename = sys.argv[1]<br>
try:<br>
  infile = open(filename, &#39;r&#39;)<br>
except:<br>
  print &quot;Can&#39;t open &quot;, filename,&quot;!&quot;<br>
  sys.exit(1)<br>
indata = csv.reader(infile, delimiter=&#39;:&#39;)<br>
<br>
loc = indata.next()      # only one field on first line<br>
parmlist = indata.next() # the list of chemicals<br>
<br>
outfile = open(&#39;out.csv&#39;, &#39;w&#39;)<br>
outdata = csv.writer(outfile, delimiter = &#39;|&#39;, lineterminator = &#39;\n&#39;)<br>
<br>
i = 0<br>
j = 0<br>
<br>
for row in indata:<br>
  outdata.writerow([loc, row[i][j], parmlist[i], row[i][j+1]])<br>
<br>
  i += 1<br>
  j += 1<br>
<br>
infile.close()<br>
outfile.close()<br>
--------------------------<br>
<br>
  List indexing is not that difficult so I am embarrassed to admit that I<br>
don&#39;t see what I&#39;m doing incorrectly. A clue would be very helpful.<br>
<br>
Rich<br>
______________________________<u></u>_________________<br>
Portland mailing list<br>
<a href="mailto:Portland@python.org" target="_blank">Portland@python.org</a><br>
<a href="http://mail.python.org/mailman/listinfo/portland" target="_blank">http://mail.python.org/<u></u>mailman/listinfo/portland</a><br>
</blockquote></div><br></div></div>