There must be a better way

Chris Rebert clp2 at rebertia.com
Sat Apr 20 19:57:05 EDT 2013


On Sat, Apr 20, 2013 at 4:46 PM, Colin J. Williams <cjw at ncf.ca> wrote:
> Below is part of a script which shows the changes made to permit the script
> to run on either Python 2.7 or Python 3.2.
>
> I was surprised to see that the CSV next method is no longer available.
>
> Suggestions welcome.
<snip>
>     if ver == '2':
>        headerLine= inData.next()
>     else:  # Python version 3.3
<snip>
>         headerLine= inData.__next__()

Use the built-in next() function
(http://docs.python.org/2/library/functions.html#next ) instead:
    headerLine = next(iter(inData))

Cheers,
Chris



More information about the Python-list mailing list