[portland] Reformatting Data Files
kyle at bucebuce.com
Tue Feb 1 22:07:01 CET 2011
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 <rshepard at appl-ecosys.com>wrote:
> On Fri, 28 Jan 2011, Kyle Jones wrote:
> It isn't anything pretty, but I think this might be similar:
> 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,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
> 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:
> outdata.writerow([location, sampdate[i], row, row[i]])
> When I change the csv.writer() method to 'csv.writer(outfile, quotechar =
> "'", delimiter = ':')' no text is quoted, including Alkalinity, Bicarbonate
> What have I missed in reading the csv module page?
> Thanks all,
> Portland mailing list
> Portland at python.org
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Portland