Path: csiph.com!usenet.pasdenom.info!news.albasani.net!newsfeed.freenet.ag!news2.euro.net!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.039 X-Spam-Evidence: '*H*': 0.92; '*S*': 0.00; 'output': 0.04; 'cpython': 0.05; 'brackets': 0.09; 'exercise': 0.13; 'sections': 0.13; '","': 0.16; '2.7.3': 0.16; 'csv': 0.16; 'dropping': 0.16; 'row': 0.16; 'subject:reader': 0.16; 'typo': 0.16; 'wanted.': 0.16; 'wrote:': 0.17; 'changes': 0.20; 'import': 0.21; 'header:In-Reply-To:1': 0.25; 'header:User-Agent:1': 0.26; 'am,': 0.27; 'correct': 0.28; 'run': 0.28; 'index,': 0.29; 'code': 0.31; 'print': 0.32; 'goes': 0.33; 'to:addr:python-list': 0.33; 'third': 0.34; 'add': 0.36; 'really': 0.36; 'but': 0.36; 'display': 0.36; 'two': 0.37; 'data': 0.37; 'subject:: ': 0.38; 'fact': 0.38; 'to:addr:python.org': 0.39; 'received:192': 0.39; 'space': 0.39; 'skip:" 10': 0.40; 'received:192.168': 0.40; 'your': 0.60; 'address': 0.60; 'first': 0.61; 'telephone': 0.64; 'here': 0.65; 'received:74.208': 0.71; 'power': 0.74; 'square': 0.75; 'barn': 0.84; 'fourth': 0.84; 'birthday': 0.91; 'ministry': 0.93 Date: Sun, 24 Mar 2013 09:03:31 -0400 From: Dave Angel User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130308 Thunderbird/17.0.4 MIME-Version: 1.0 To: python-list@python.org Subject: Re: Separate Rows in reader References: <5a1660c3-ca17-452c-ae0f-ee61f4319a8f@googlegroups.com> In-Reply-To: <5a1660c3-ca17-452c-ae0f-ee61f4319a8f@googlegroups.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Provags-ID: V02:K0:Q2CWYjIe5yHOk8hBY13DG/dZSDkbnrnx5l8cwGh+PCm lpA7Ri5tXaZsOSAQuJVUDosp4KEa0wIPGLC0wnOV8eAyjpv1G+ 6bmBVh9XTVpsM2j90dqWkxz1E8BaH42D54HG9LCYiqD3hF1A6S Oodkw/jBd22LunzcpnbtGCTmXJzDbVIb1gP5ySqqcBdrew4Rk3 BkDqsszGE96ddDUM6Fz1/i0TSNJ5qqZlAuQroYvUnon3H+nrkN Nz/ftqhA+cg4WFpYCquXe63h4fURN3NfwcSaKTm9BS3e9rtxF1 ov9wp5q8pJonXl6O9tyB3WfHXSbBBgOQwlKqj5htok68RyaNw= = 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: 61 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1364130228 news.xs4all.nl 6904 [2001:888:2000:d::a6]:44402 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:41779 On 03/24/2013 04:11 AM, Jiewei Huang wrote: > >> >> > > Sorry my typo in the output here is the correct output that i need : > > [('John Konon', 'Ministry of moon Walks', '4567882', '27-Feb'), > ( 'Stacy Kisha', 'Ministry of Man Power', '1234567', 17-Jan')] > > the difference is that i need a [(row two), (row three), (row fouth)] . I do not want to display row one which is ['Name', ' Address', 'Telephone', 'Birthday'] > I had to add a delimiter= to accomodate the fact that your data is tab- separated. The first two code sections address the dropping of row-zero. The third section changes the square brackets to parens, if that's what you really wanted. The fourth section goes all around the barn to get the linefeeds in the right place. There's still one extra space on the first line, but that's an exercise for the reader. run with CPython 2.7.3 import csv original = [ "Name Address Telephone Birthday ", "John Konon Ministry of Moon Walks 4567882 27-Feb", "Stacy Kisha Ministry of Man Power 1234567 17-Jan" ] #original = file('friends.csv', 'rU') reader = csv.reader(original, delimiter="\t") for index, row in enumerate(reader): if index: print row print "-----------" reader = csv.reader(original, delimiter="\t") data = list(reader)[1:] print data print "-----------" reader = csv.reader(original, delimiter="\t") data = [tuple(row) for row in list(reader)[1:]] print data print "-----------" reader = csv.reader(original, delimiter="\t") data = [tuple(row) for row in list(reader)[1:]] print "[", for row in data[:-1]: print str(row) + "," print str(data[-1]) +"]" print "-----------" -- DaveA