next() in python does not work. What is an alternative to reading next line in Python? Here is a sample:
filne = "D:/testtube/testdkanimfilternode.txt"
f = open(filne, 'r+')
while 1:
lines = f.readlines()
if not lines:
break
for line in lines:
print line
if (line[:5] == "anim "):
print 'next() '
ne = f.next()
print ' ne ',ne,'\n'
break
f.close()
Running this on a file does not show ‘ne ‘.
next()does not work in your case because you first callreadlines()which basically sets the file iterator to point to the end of file.Since you are reading in all the lines anyway you can refer to the next line using an index: