fileinput.input, readlines and ...
Private Private
mail131 at gmail.com
Wed Jun 24 16:17:35 EDT 2009
On Jun 24, 1:32 pm, Peter Otten <__pete... at web.de> wrote:
> Przemyslaw Bak wrote:
> > Hello,
>
> > I many files with log data. The structure of the file is quite
> > inconvenience and similar to the following example:
> > Data1
> > ValueA
> > Data2
> > ValueB
> > Data3
> > ValueC
> > ...
> > To get the values I need to find Data* and then get to the next line.
> > I tried to use fileinput.input :
> > ...
> > for line in fileinput.input(filename):
> > if line.find("Data2") >= 0:
> > (now what ?)
>
> > So I can find the requested line (Data2) but how to get value from the
> > next line ?
>
> 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
More information about the Python-list
mailing list