fileinput.input, readlines and ...
Peter Otten
__peter__ at web.de
Wed Jun 24 17:00:27 EDT 2009
Private Private wrote:
> > lines = fileinput.input(filename)
> > for line in lines:
> > if "Data2" in line:
> > print line.strip(), "-->", next(lines).strip()
>
> I get an error:
>
> ...
> print line.strip(), "-->", next(lines).strip()
> NameError: global name 'next' is not defined
In Python versions prior to 2.6 instead of
next(lines)
you can use
lines.next()
Peter
More information about the Python-list
mailing list