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.002 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'else:': 0.03; 'received:134': 0.05; 'cc:addr:python-list': 0.11; 'python': 0.11; 'def': 0.12; '2.7': 0.14; 'instead:': 0.16; 'main():': 0.16; 'subject:There': 0.16; 'to:addr:web.de': 0.16; 'used:': 0.16; 'wrote:': 0.18; 'slightly': 0.19; 'cc:addr:python.org': 0.22; 'header:User-Agent:1': 0.23; 'williams': 0.24; 'cc:2**0': 0.24; 'cc:no real name:2**0': 0.24; "i've": 0.25; 'header:In-Reply- To:1': 0.27; 'function': 0.29; 'chris': 0.29; 'am,': 0.29; 'statement': 0.30; 'code': 0.31; 'dropped': 0.31; 'end,': 0.31; 'url:python': 0.33; 'but': 0.35; 'acceptable': 0.36; 'url:org': 0.36; 'url:library': 0.38; 'mentioned': 0.61; 'skip:n 10': 0.64; 'otten': 0.84 Date: Sun, 21 Apr 2013 11:30:53 -0400 From: "Colin J. Williams" User-Agent: Mozilla/5.0 (Windows NT 5.1; rv:17.0) Gecko/20130328 Thunderbird/17.0.5 MIME-Version: 1.0 Newsgroups: comp.lang.python To: Peter Otten <__peter__@web.de> Subject: Re: There must be a better way References: <51732d81$0$29977$c3e8da3$5496439d@news.astraweb.com> <20130420193422.25255e98@bigbox.christie.dr> In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-NCF-Filtered: By ProxSMTP on pallando Sun Apr 21 11:30:26 2013 -0400 (EDT) X-AV-Checked: ClamAV using ClamSMTP 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: , Message-ID: Lines: 35 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1366558805 news.xs4all.nl 2264 [2001:888:2000:d::a6]:33786 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:44011 On 21/04/2013 9:43 AM, Peter Otten wrote: > Colin J. Williams wrote: > >> I was seeking some code that would be acceptable to both Python 2.7 and >> 3.3. >> >> In the end, I used: >> >> inData= csv.reader(inFile) >> >> def main(): >> if ver == '2': >> headerLine= inData.next() >> else: >> headerLine= inData.__next__() >> ... > > I think it was mentioned before, but to be explicit: > > def main(): > headerLine = next(inData) > ... > > works in Python 2.6, 2.7, and 3.x. > Yes, the penny dropped eventually. I've used your statement The Chris suggestion was slightly different: Use the built-in next() function (http://docs.python.org/2/library/functions.html#next ) instead: headerLine = next(iter(inData)) Colin W.