There must be a better way

Peter Otten __peter__ at web.de
Sun Apr 21 09:43:52 EDT 2013


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.




More information about the Python-list mailing list