[Tutor] reading an input stream

Danny Yoo dyoo at hashcollision.org
Thu Dec 24 22:26:33 EST 2015


>>>> numStream.next()
> Traceback (most recent call last):
>   File "<pyshell#3>", line 1, in <module>
>     numStream.next()
> AttributeError: 'generator' object has no attribute 'next'
>
>
> If I instead do this:
>
>>>> next(numStream)
> 0
>>>> next(numStream)
> 1
>>>> next(numStream)
> 2
>
> Things work as you described.  Is your example from Python 2?  If yes,
> is this something that changed between Python 2 and 3?  I have not
> made it to generators yet, but you have now whetted my appetite!


Hi BoB,

Ah, yes, thank you!  Yes, I was using Python 2.  I'll have to set up
Python 3 on my server and get some more experience with it during the
break, then!

Let me double check the docs... ok, yeah, I should be using the next()
function, since that's available in Python 2 as well.  Reference:
https://docs.python.org/2/library/functions.html#next


More information about the Tutor mailing list