Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #44010
| Path | csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!news.etla.org!nntp-feed.chiark.greenend.org.uk!ewrotcd!news.xcski.com!ncf.ca!not-for-mail |
|---|---|
| From | "Colin J. Williams" <cjw@ncf.ca> |
| Newsgroups | comp.lang.python |
| Subject | Re: There must be a better way |
| Date | Sun, 21 Apr 2013 11:30:53 -0400 |
| Organization | National Capital Freenet, Ottawa, Ontario, Canada |
| Lines | 35 |
| Sender | fn681@206-47-113-144.dsl.ncf.ca |
| Message-ID | <5174062D.2090009@ncf.ca> (permalink) |
| 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> <mailman.878.1366551835.3114.python-list@python.org> |
| NNTP-Posting-Host | 206-47-113-144.dsl.ncf.ca |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=UTF-8; format=flowed |
| Content-Transfer-Encoding | 7bit |
| X-Trace | theodyn.ncf.ca 1366558224 3795 206.47.113.144 (21 Apr 2013 15:30:24 GMT) |
| X-Complaints-To | complaints@ncf.ca |
| NNTP-Posting-Date | 21 Apr 2013 15:30:24 GMT |
| Cc | python-list@python.org |
| To | Peter Otten <__peter__@web.de> |
| User-Agent | Mozilla/5.0 (Windows NT 5.1; rv:17.0) Gecko/20130328 Thunderbird/17.0.5 |
| In-Reply-To | <mailman.878.1366551835.3114.python-list@python.org> |
| Xref | csiph.com comp.lang.python:44010 |
Show key headers only | View raw
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.
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