fileinput.input, readlines and ...

Private Private mail131 at gmail.com
Thu Jun 25 06:57:36 CEST 2009


On Jun 24, 11:00 pm, Peter Otten <__pete... at web.de> wrote:
> 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

That works perfectly. Thank you :-)



More information about the Python-list mailing list