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: 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 Date: Wed, 6 May 2015 12:27:31 -0600 Subject: Re: Writing list of dictionaries to CSV To: Python 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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: 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 On Wed, May 6, 2015 at 12:22 PM, Tim Chase 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.