This code below works correct :
def file_gen(f_name):
f = open(f_name)
for line in f:
yield line
gen_line = file_gen("foo.html")
gen_line.next() # '<!DOCTYPE>\n'
gen_line.next() # '<html> \n'
gen_line.next() # ... next line in file
But this function raises StopIteration
. I don't understand why ?
def file_gen(f_name):
f = open(f_name)
line = f.readline()
yield line
gen_line = file_gen('foo.html')
gen_line.next() # '<!DOCTYPE>\n'
gen_line.next() # StopIteration
yield
line) – Kiosk