I didn't test it, but you probably want quoting=csv.QUOTE_NONNUMERIC You will then need to convert that value (which was read in as a string) to an integer/whatever-numeric-form before writing it.
On Tue, Feb 1, 2011 at 12:46 PM, Rich Shepard <[email protected]>wrote: > On Fri, 28 Jan 2011, Kyle Jones wrote: > > It isn't anything pretty, but I think this might be similar: >> http://paste.pocoo.org/show/328545/ >> > > Kyle/John/Ethan/Dylan/Jerry, > > Pretty enough. > > What I still need to figure out is why csv.writer() is not writing proper > delimited output. Here's an example of output lines: > > JCM-20B,2008-11-13,Depth to Water,97.08 > JCM-20B,2008-11-13,pH,7.40 > JCM-20B,2008-11-13,Total Dissolved Solids,211 > JCM-20B,2008-11-13,"Alkalinity, Bicarbonate",167 > > Notice that the third item is not quoted unless the text contains a comma. > What I want for output is to have all text fields (that is, all but the > last > one) quoted, preferably with single quotes to keep postgres happy. > > This output is produced by: > > outfile = open('out.csv', 'w') > outdata = csv.writer(outfile) > > for row in indata: > for i, location in enumerate(loc): > if i == 0: > continue > outdata.writerow([location, sampdate[i], row[0], row[i]]) > > When I change the csv.writer() method to 'csv.writer(outfile, quotechar = > "'", delimiter = ':')' no text is quoted, including Alkalinity, Bicarbonate > above. > > What have I missed in reading the csv module page? > > Thanks all, > > > Rich > > > > _______________________________________________ > Portland mailing list > [email protected] > http://mail.python.org/mailman/listinfo/portland > -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.python.org/pipermail/portland/attachments/20110201/2c1ced97/attachment.html> _______________________________________________ Portland mailing list [email protected] http://mail.python.org/mailman/listinfo/portland
