Search code examples
pythoniterator

Python: next() is not recognized


When I do next(ByteIter, '')<<8 in python, I got a name error saying

"global name 'next' is not defined"

I'm guessing this function is not recognized because of python version? My version is 2.5.


Solution

  • From the docs

    next(iterator[, default])

    Retrieve the next item from the iterator by calling its next() method. 
    If default is given, it is returned if the iterator is
    exhausted, otherwise StopIteration is raised.
    
    New in version 2.6.
    

    So yes, it does require version 2.6.