Path: csiph.com!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed1a.news.xs4all.nl!xs4all!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.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'subject:text': 0.05; 'binary': 0.07; 'subject:file': 0.07; 'lawrence': 0.09; 'newline': 0.09; 'subject:into': 0.09; 'cc:addr:python-list': 0.11; 'python': 0.11; '-tkc': 0.16; 'csv': 0.16; 'expects': 0.16; 'from:addr:python.list': 0.16; 'from:addr:tim.thechases.com': 0.16; 'from:name:tim chase': 0.16; 'mode,': 0.16; 'wrote:': 0.18; 'module': 0.19; 'version.': 0.19; 'examples': 0.20; 'cc:addr:python.org': 0.22; 'this?': 0.23; 'fine': 0.24; 'file.': 0.24; 'cc:2**0': 0.24; 'cc:no real name:2**0': 0.24; "i've": 0.25; 'handling': 0.26; 'header:In-Reply-To:1': 0.27; '[1]': 0.29; 'mode': 0.30; 'especially': 0.30; 'that.': 0.31; 'file': 0.32; 'open': 0.33; 'url:python': 0.33; 'objects': 0.35; 'charset:us- ascii': 0.36; 'url:org': 0.36; 'url:library': 0.38; 'little': 0.38; 'anything': 0.39; 'does': 0.39; 'read': 0.60; '2.7.': 0.84; 'received:50.22': 0.84; 'to:addr:yahoo.co.uk': 0.84 Date: Thu, 6 Feb 2014 11:51:16 -0600 From: Tim Chase To: Mark Lawrence Subject: Re: parse a csv file into a text file In-Reply-To: References: <5c268845-003f-4e24-b27a-c89e9fbfcc6c@googlegroups.com> X-Mailer: Claws Mail 3.8.1 (GTK+ 2.24.10; x86_64-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Authenticated-Sender: tim@thechases.com X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - boston.accountservergroup.com X-AntiAbuse: Original Domain - python.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - tim.thechases.com X-Get-Message-Sender-Via: boston.accountservergroup.com: authenticated_id: tim@thechases.com Cc: python-list@python.org X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 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: 23 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1391709038 news.xs4all.nl 2853 [2001:888:2000:d::a6]:44014 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:65545 On 2014-02-06 17:40, Mark Lawrence wrote: > On 06/02/2014 14:02, Neil Cerutti wrote: > > > > You must open the file in binary mode, as that is what the csv > > module expects in Python 2.7. newline handling can be enscrewed > > if you forget. > > > > file = open('raw.csv', 'b') > > > > I've never opened a file in binary mode to read with the csv module > using any Python version. Where does it state that you must do > this? While the docs don't currently say anything about it, all the examples at [1] use 'rb' or 'wb' when opening the file. I've long wondered about that. Especially as I've passed non-file objects like lists/iterators to the csv.reader/csv.DictReader and had them work just fine (and would be a little perturbed if they broke). -tkc [1] http://docs.python.org/2/library/csv.html