Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #90068

Re: Writing list of dictionaries to CSV

Path csiph.com!usenet.pasdenom.info!news.redatomik.org!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <ian.g.kelly@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.004
X-Spam-Evidence '*H*': 0.99; '*S*': 0.00; 'mrab': 0.05; 'tries': 0.07; 'string': 0.09; '*is*': 0.09; 'string;': 0.09; ':-(': 0.16; 'csv': 0.16; 'quoted': 0.16; 'subject:CSV': 0.16; 'subject:Writing': 0.16; 'subject:dictionaries': 0.16; ':-)': 0.16; 'wrote:': 0.18; 'wed,': 0.18; 'file,': 0.19; 'tests': 0.22; 'regardless': 0.24; 'looks': 0.24; 'source': 0.25; 'excel': 0.26; 'values': 0.27; 'header:In-Reply-To:1': 0.27; 'tried': 0.27; 'tim': 0.29; "doesn't": 0.30; 'subject:list': 0.30; 'message- id:@mail.gmail.com': 0.30; 'chase': 0.31; 'skip:q 20': 0.31; "they'll": 0.31; 'though.': 0.31; 'could': 0.34; 'received:google.com': 0.35; 'to:addr:python-list': 0.38; 'pm,': 0.38; 'quote': 0.39; 'to:addr:python.org': 0.39; 'tell': 0.60; 'hope': 0.61; 'field.': 0.61; 'number:': 0.66; '2015': 0.84
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type; bh=VKSKT4jLkuVrqFBs0882ivnksrtiJ6dLX30cfecq0so=; b=nbAoqIG987TxHfR2VUs6YWKhoq/wOLrCBqVb1xxj7SLvzsmqkJkIUsOzPvDECkiTlh H3yc/zuz1/hXZLCxSQEp3fg9mtHIZr3eMA/qaDWzzUScKjg6TpzKdVht9/4EYl36pL2N MkVrgLWHVmsmhSJUxRsuIwKx022Kv3whsy8lzEEgpD6gNVQyzm4UvxhJMtjqZkGOWvQK +PzsLk55nJWw2OCMvhvSbWDm9qmW7w+xYhpi0Oflxq7qqp8EauoidD2ijNUq7KBRNV7c IAD0iP3TWTmzLoD7IDWcA2vpSbhvyztApSNNBvP9sdm0NQPwt8C+54l7b18PBkcJ4Szj v1xQ==
X-Received by 10.107.136.89 with SMTP id k86mr32006iod.63.1430936892195; Wed, 06 May 2015 11:28:12 -0700 (PDT)
MIME-Version 1.0
In-Reply-To <20150506132255.510c2eec@bigbox.christie.dr>
References <5bd0afb3-d2d4-469f-be39-5869f01adc92@googlegroups.com> <072badd6-0542-468a-99bd-cc3a4ffc7156@googlegroups.com> <554A58B4.80700@mrabarnett.plus.com> <20150506132255.510c2eec@bigbox.christie.dr>
From Ian Kelly <ian.g.kelly@gmail.com>
Date Wed, 6 May 2015 12:27:31 -0600
Subject Re: Writing list of dictionaries to CSV
To Python <python-list@python.org>
Content-Type text/plain; charset=UTF-8
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.20+
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.185.1430936901.12865.python-list@python.org> (permalink)
Lines 24
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1430936901 news.xs4all.nl 2905 [2001:888:2000:d::a6]:56781
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:90068

Show key headers only | View raw


On Wed, May 6, 2015 at 12:22 PM, Tim Chase
<python.list@tim.thechases.com> wrote:
> On 2015-05-06 19:08, MRAB wrote:
>> You could tell it to quote any value that's not a number:
>>
>>       w = csv.DictWriter(f, pol_keys,
>> quoting=csv.QUOTE_NONNUMERIC)
>>
>> It looks like all of the values you have are strings, so they'll
>> all be quoted.
>>
>> I would hope that Excel will then treat it as a string; it would be
>> stupid if it didn't! :-)
>
> Sadly, Excel *is* that stupid based on the tests I tried just now. :-(
>
> Regardless of whether "Mar 2015" is quoted or unquoted in the source
> CSV file, Excel tries to outwit you and mangles the presentation.

Quoting a value in csv doesn't mean it's a string; it just means that
it's a single field.

You *can* force Excel to treat a value as a string by prefixing it
with an apostrophe, though.

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Writing list of dictionaries to CSV Kashif Rana <kashifrana84@gmail.com> - 2015-05-05 10:09 -0700
  Re: Writing list of dictionaries to CSV MRAB <python@mrabarnett.plus.com> - 2015-05-05 19:11 +0100
  Re: Writing list of dictionaries to CSV Skip Montanaro <skip.montanaro@gmail.com> - 2015-05-05 13:25 -0500
  Re: Writing list of dictionaries to CSV Cecil Westerhof <Cecil@decebal.nl> - 2015-05-05 20:44 +0200
  Re: Writing list of dictionaries to CSV Matthew Ruffalo <mmr15@case.edu> - 2015-05-05 15:43 -0400
  Re: Writing list of dictionaries to CSV Tim Chase <python.list@tim.thechases.com> - 2015-05-05 12:34 -0500
  Re: Writing list of dictionaries to CSV Kashif Rana <kashifrana84@gmail.com> - 2015-05-05 22:32 -0700
    Re: Writing list of dictionaries to CSV Chris Angelico <rosuav@gmail.com> - 2015-05-06 16:34 +1000
    Re: Writing list of dictionaries to CSV Cecil Westerhof <Cecil@decebal.nl> - 2015-05-06 08:50 +0200
    Re: Writing list of dictionaries to CSV Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2015-05-06 09:14 -0400
    Re: Writing list of dictionaries to CSV MRAB <python@mrabarnett.plus.com> - 2015-05-06 19:08 +0100
    Re: Writing list of dictionaries to CSV Tim Chase <python.list@tim.thechases.com> - 2015-05-06 13:22 -0500
    Re: Writing list of dictionaries to CSV Ian Kelly <ian.g.kelly@gmail.com> - 2015-05-06 12:27 -0600
    Re: Writing list of dictionaries to CSV Tim Chase <python.list@tim.thechases.com> - 2015-05-06 13:37 -0500
    Re: Writing list of dictionaries to CSV Denis McMahon <denismfmcmahon@gmail.com> - 2015-05-06 23:31 +0000
      Re: Writing list of dictionaries to CSV Tim Chase <python.list@tim.thechases.com> - 2015-05-06 20:22 -0500
      Re: Writing list of dictionaries to CSV Jon Ribbens <jon+usenet@unequivocal.co.uk> - 2015-05-07 01:55 +0000
      Re: Writing list of dictionaries to CSV [correction] Tim Chase <python.list@tim.thechases.com> - 2015-05-06 20:52 -0500

csiph-web