Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #44078
| Path | csiph.com!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <oscar.j.benjamin@gmail.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.011 |
| X-Spam-Evidence | '*H*': 0.98; '*S*': 0.00; 'else:': 0.03; 'win32': 0.03; 'cc:addr:python-list': 0.11; 'python': 0.11; 'def': 0.12; "'rb')": 0.16; 'csv': 0.16; 'main():': 0.16; 'subject:There': 0.16; 'used:': 0.16; "{'a':": 0.16; 'wrote:': 0.18; 'bit': 0.19; '>>>': 0.22; 'import': 0.22; 'cc:addr:python.org': 0.22; 'williams': 0.24; 'cc:2**0': 0.24; 'cc:no real name:2**0': 0.24; '2010,': 0.27; 'header:In-Reply-To:1': 0.27; 'message- id:@mail.gmail.com': 0.30; 'assert': 0.31; 'end,': 0.31; 'received:209.85': 0.35; 'received:209.85.220': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'doing': 0.36; 'received:209': 0.37; 'nov': 0.38; "you're": 0.61; 'more': 0.64; "'2'}": 0.84; "'3',": 0.84; '2.7.1': 0.84; 'oscar': 0.84; '2013': 0.98 |
| DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=x-received:mime-version:in-reply-to:references:from:date:message-id :subject:to:cc:content-type; bh=07/PcenslpgFMpmNbBpCoaq/lvuuUj0i3DXMWcYtWbo=; b=OrgcuQV/Y5+P1zn82XezUz/fGSvCFAcxfZF4ACd72C8mQs7/mTX9mWUqy1oUq59Y5b kVH7jvti7mJzDSkjf06EJo0azRWhe5uYuIo6NIW0t/JliA/2P+nu0bDVwn2WQOO5ko6d tWxj+T8NMI5/r9o5G1hT5pZAdCGjfFCmm/VWKV7+6Xlf8rrz5DcvOjwupoUY5oXRYaNe 1AAFFphB49JEP+Aa5z7V0Rn+X5kv5N4o+ZyEx1Uuv3JbBuk2ljKDZz5a6WeGsRGar5TF WB7VFQKVvz4AYnNbH+PoEqyaa1mTtX0xSeHdqPZWXLL/462fW9xQCutHuoIZkDhUSIi3 ScYw== |
| X-Received | by 10.52.100.193 with SMTP id fa1mr4151306vdb.46.1366641144052; Mon, 22 Apr 2013 07:32:24 -0700 (PDT) |
| MIME-Version | 1.0 |
| In-Reply-To | <kl0opb$pcr$1@theodyn.ncf.ca> |
| References | <kkv9bt$9bm$1@theodyn.ncf.ca> <51732d81$0$29977$c3e8da3$5496439d@news.astraweb.com> <20130420193422.25255e98@bigbox.christie.dr> <mailman.869.1366506610.3114.python-list@python.org> <kl0opb$pcr$1@theodyn.ncf.ca> |
| From | Oscar Benjamin <oscar.j.benjamin@gmail.com> |
| Date | Mon, 22 Apr 2013 15:32:03 +0100 |
| Subject | Re: There must be a better way |
| To | "Colin J. Williams" <cjw@ncf.ca> |
| Content-Type | text/plain; charset=ISO-8859-1 |
| 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 <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.918.1366641146.3114.python-list@python.org> (permalink) |
| Lines | 38 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1366641146 news.xs4all.nl 2176 [2001:888:2000:d::a6]:48189 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:44078 |
Show key headers only | View raw
On 21 April 2013 14:15, Colin J. Williams <cjw@ncf.ca> wrote:
> In the end, I used:
>
> inData= csv.reader(inFile)
>
> def main():
>
> if ver == '2':
> headerLine= inData.next()
> else:
> headerLine= inData.__next__()
> ...
> for item in inData:
> assert len(dataStore) == len(item)
> j= findCardinal(item[10])
> ...
This may not be relevant for what you're doing but if you use
csv.DictReader there's no need to retrieve the top line separately:
$ cat tmp.csv
a,b,c
1,2,3
4,5,6
$ python
Python 2.7.1 (r271:86832, Nov 27 2010, 18:30:46) [MSC v.1500 32 bit
(Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import csv
>>> with open('tmp.csv', 'rb') as csvfile:
... for row in csv.DictReader(csvfile):
... print(row)
...
{'a': '1', 'c': '3', 'b': '2'}
{'a': '4', 'c': '6', 'b': '5'}
Oscar
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
There must be a better way "Colin J. Williams" <cjw@ncf.ca> - 2013-04-20 19:46 -0400
Re: There must be a better way Chris Rebert <clp2@rebertia.com> - 2013-04-20 16:57 -0700
Re: There must be a better way Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-04-21 00:06 +0000
Re: There must be a better way Tim Chase <python.list@tim.thechases.com> - 2013-04-20 19:34 -0500
Re: There must be a better way Terry Jan Reedy <tjreedy@udel.edu> - 2013-04-20 21:07 -0400
Re: There must be a better way "Colin J. Williams" <cjw@ncf.ca> - 2013-04-21 09:15 -0400
Re: There must be a better way Jussi Piitulainen <jpiitula@ling.helsinki.fi> - 2013-04-21 16:39 +0300
Re: There must be a better way "Colin J. Williams" <cjw@ncf.ca> - 2013-04-21 11:17 -0400
Re: There must be a better way Peter Otten <__peter__@web.de> - 2013-04-21 15:43 +0200
Re: There must be a better way "Colin J. Williams" <cjw@ncf.ca> - 2013-04-21 11:30 -0400
Re: There must be a better way "Colin J. Williams" <cjw@ncf.ca> - 2013-04-21 11:30 -0400
Re: There must be a better way Oscar Benjamin <oscar.j.benjamin@gmail.com> - 2013-04-22 15:32 +0100
Re: There must be a better way Neil Cerutti <neilc@norwich.edu> - 2013-04-22 14:42 +0000
Re: There must be a better way "Colin J. Williams" <cjw@ncf.ca> - 2013-04-22 13:44 -0400
Re: There must be a better way Neil Cerutti <neilc@norwich.edu> - 2013-04-23 13:36 +0000
Re: There must be a better way Oscar Benjamin <oscar.j.benjamin@gmail.com> - 2013-04-23 15:15 +0100
Re: There must be a better way Tim Chase <python.list@tim.thechases.com> - 2013-04-23 09:30 -0500
Re: There must be a better way Skip Montanaro <skip@pobox.com> - 2013-04-23 09:36 -0500
Re: There must be a better way (correction) Tim Chase <python.list@tim.thechases.com> - 2013-04-23 10:02 -0500
csiph-web