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: 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: References: <51732d81$0$29977$c3e8da3$5496439d@news.astraweb.com> <20130420193422.25255e98@bigbox.christie.dr> From: Oscar Benjamin Date: Mon, 22 Apr 2013 15:32:03 +0100 Subject: Re: There must be a better way To: "Colin J. Williams" 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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: 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 On 21 April 2013 14:15, Colin J. Williams 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