Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!feeds.phibee-telecom.net!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.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'subject:text': 0.05; 'binary': 0.07; 'subject:file': 0.07; 'newline': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'subject:into': 0.09; 'python': 0.11; 'csv': 0.16; 'expects': 0.16; 'mode,': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'wrote:': 0.18; 'module': 0.19; 'import': 0.22; 'header:User- Agent:1': 0.23; 'parse': 0.24; 'handling': 0.26; 'second': 0.26; 'header:X-Complaints-To:1': 0.27; 'file': 0.32; 'text': 0.33; 'open': 0.33; 'charset:us-ascii': 0.36; 'hi,': 0.36; 'to:addr :python-list': 0.38; 'to:addr:python.org': 0.39; 'received:org': 0.40; '2.7.': 0.84; 'zhang': 0.84; 'toronto': 0.91 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Neil Cerutti Subject: Re: parse a csv file into a text file Date: Thu, 6 Feb 2014 14:02:31 +0000 (UTC) Organization: Norwich University References: <5c268845-003f-4e24-b27a-c89e9fbfcc6c@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Gmane-NNTP-Posting-Host: jackman.norwich.edu User-Agent: slrn/0.9.9p1/mm/ao (Win32) 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: 31 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1391695381 news.xs4all.nl 2974 [2001:888:2000:d::a6]:34093 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:65539 On 2014-02-06, Zhen Zhang wrote: > Hi, every one. > > I am a second year EE student. > I just started learning python for my project. > > I intend to parse a csv file with a format like > > 3520005,"Toronto (Ont.)",C > ,F,2503281,2481494,F,F,0.9,1040597,979330,630.1763,3972.4,1 [...] into a text file like the following > > Toronto 2503281 [...] > This is what i have so far. > > > [code] > > import csv > file = open('raw.csv') 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') -- Neil Cerutti