I didn't test it, but you probably want quoting=csv.QUOTE_NONNUMERIC<div><br></div><div><div>You will then need to convert that value (which was read in as a string) to an integer/whatever-numeric-form before writing it.</div>
<div><br></div><div><br><div class="gmail_quote">On Tue, Feb 1, 2011 at 12:46 PM, Rich Shepard <span dir="ltr"><<a href="mailto:rshepard@appl-ecosys.com">rshepard@appl-ecosys.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<div class="im">On Fri, 28 Jan 2011, Kyle Jones wrote:<br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
It isn't anything pretty, but I think this might be similar:<br>
<a href="http://paste.pocoo.org/show/328545/" target="_blank">http://paste.pocoo.org/show/328545/</a><br>
</blockquote>
<br></div>
Kyle/John/Ethan/Dylan/Jerry,<br>
<br>
Pretty enough.<br>
<br>
What I still need to figure out is why csv.writer() is not writing proper<br>
delimited output. Here's an example of output lines:<br>
<br>
JCM-20B,2008-11-13,Depth to Water,97.08<br>
JCM-20B,2008-11-13,pH,7.40<br>
JCM-20B,2008-11-13,Total Dissolved Solids,211<br>
JCM-20B,2008-11-13,"Alkalinity, Bicarbonate",167<br>
<br>
Notice that the third item is not quoted unless the text contains a comma.<br>
What I want for output is to have all text fields (that is, all but the last<br>
one) quoted, preferably with single quotes to keep postgres happy.<br>
<br>
This output is produced by:<br>
<br>
outfile = open('out.csv', 'w')<br>
outdata = csv.writer(outfile)<br>
<br>
for row in indata:<br>
for i, location in enumerate(loc):<br>
if i == 0:<br>
continue<br>
outdata.writerow([location, sampdate[i], row[0], row[i]])<br>
<br>
When I change the csv.writer() method to 'csv.writer(outfile, quotechar =<br>
"'", delimiter = ':')' no text is quoted, including Alkalinity, Bicarbonate<br>
above.<br>
<br>
What have I missed in reading the csv module page?<br>
<br>
Thanks all,<div><div></div><div class="h5"><br>
<br>
Rich<br>
<br>
<br>
<br>
_______________________________________________<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/mailman/listinfo/portland</a><br>
</div></div></blockquote></div><br></div></div>