Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #41779
| 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 | <davea@davea.name> |
| 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 <davea@davea.name> |
| 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 | <fdcdb6d8-c63a-4909-8b56-13204a0d474c@googlegroups.com> <mailman.3662.1364104023.2939.python-list@python.org> <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 <python-list.python.org> |
| List-Unsubscribe | <http://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 | <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.3666.1364130228.2939.python-list@python.org> (permalink) |
| 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 |
Show key headers only | View raw
On 03/24/2013 04:11 AM, Jiewei Huang wrote:
>
>> <SNIP all those quoted lines doubled by anti-social googlegroups>
>>
>
> 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
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Separate Rows in reader Jiewei Huang <jiewei24@gmail.com> - 2013-03-23 22:20 -0700
Re: Separate Rows in reader Dave Angel <davea@davea.name> - 2013-03-24 01:46 -0400
Re: Separate Rows in reader rusi <rustompmody@gmail.com> - 2013-03-24 00:34 -0700
Re: Separate Rows in reader Jiewei Huang <jiewei24@gmail.com> - 2013-03-24 01:18 -0700
Re: Separate Rows in reader Jiewei Huang <jiewei24@gmail.com> - 2013-03-24 01:11 -0700
Re: Separate Rows in reader Dave Angel <davea@davea.name> - 2013-03-24 09:03 -0400
Re: Separate Rows in reader Tim Chase <python.list@tim.thechases.com> - 2013-03-24 08:49 -0500
Re: Separate Rows in reader rusi <rustompmody@gmail.com> - 2013-03-24 08:57 -0700
Re: Separate Rows in reader Tim Chase <python.list@tim.thechases.com> - 2013-03-24 13:28 -0500
Re: Separate Rows in reader rusi <rustompmody@gmail.com> - 2013-03-24 19:08 -0700
Re: Separate Rows in reader Jiewei Huang <jiewei24@gmail.com> - 2013-03-24 01:11 -0700
Re: Separate Rows in reader ypsun <winter0128@gmail.com> - 2013-03-24 03:58 -0700
Re: Separate Rows in reader ypsun <winter0128@gmail.com> - 2013-03-24 04:10 -0700
Re: Separate Rows in reader Jiewei Huang <jiewei24@gmail.com> - 2013-03-24 23:52 -0700
Re: Separate Rows in reader rusi <rustompmody@gmail.com> - 2013-03-25 06:51 -0700
Re: Separate Rows in reader Jiewei Huang <jiewei24@gmail.com> - 2013-03-25 18:05 -0700
Re: Separate Rows in reader Dave Angel <davea@davea.name> - 2013-03-25 21:40 -0400
Re: Separate Rows in reader Jiewei Huang <jiewei24@gmail.com> - 2013-03-25 20:33 -0700
Re: Separate Rows in reader MRAB <python@mrabarnett.plus.com> - 2013-03-26 03:48 +0000
Re: Separate Rows in reader Jiewei Huang <jiewei24@gmail.com> - 2013-03-26 00:24 -0700
Re: Separate Rows in reader Jiewei Huang <jiewei24@gmail.com> - 2013-03-26 00:24 -0700
Re: Separate Rows in reader Jiewei Huang <jiewei24@gmail.com> - 2013-03-27 02:35 -0700
Re: Separate Rows in reader rusi <rustompmody@gmail.com> - 2013-03-27 04:18 -0700
Re: Separate Rows in reader Jiewei Huang <jiewei24@gmail.com> - 2013-03-27 15:12 -0700
Re: Separate Rows in reader Jiewei Huang <jiewei24@gmail.com> - 2013-03-27 15:26 -0700
Re: Separate Rows in reader rusi <rustompmody@gmail.com> - 2013-03-27 18:24 -0700
Re: Separate Rows in reader Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-03-28 01:32 +0000
Re: Separate Rows in reader Jiewei Huang <jiewei24@gmail.com> - 2013-03-27 02:35 -0700
Re: Separate Rows in reader Tim Roberts <timr@probo.com> - 2013-03-28 21:28 -0700
Re: Separate Rows in reader Jiewei Huang <jiewei24@gmail.com> - 2013-03-25 20:33 -0700
Re: Separate Rows in reader Jiewei Huang <jiewei24@gmail.com> - 2013-03-24 18:15 -0700
csiph-web