I am creating a file object and try to access the next() on it. But the interpreter throws error mentioning that the function does not exist.
open("scala.txt").next()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: '_io.TextIOWrapper' object has no attribute 'next'
But many discussions that I come across, mention that next() is available. But when I use this object in a for loop, it works fine. Can I get some help on why the above piece of code throws error.
PS: I encounter similar context when I create my own generator & try to invoke next(). When I place the generator object in a for loop, it works nicely.
>>> x = (e for e in range(1,10))
>>> x.next()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'generator' object has no attribute 'next'
Thanks!