Re: fileinput.input, readlines and ...

2009-06-26 Thread Kushal Kumaran
On Thu, Jun 25, 2009 at 10:32 AM, Private Private wrote: > On Jun 24, 12:23 pm, Przemyslaw Bak wrote: >> Hello, >> >> I many files with log data. The structure of the file is quite > > Each requested value is in separated file. > While traversing using os.path.walk I have noticed that I get files

Re: fileinput.input, readlines and ...

2009-06-24 Thread Private Private
On Jun 24, 12:23 pm, Przemyslaw Bak wrote: > Hello, > > I many files with log data. The structure of the file is quite Each requested value is in separated file. While traversing using os.path.walk I have noticed that I get files unsorted. Is it possible to get them sorted ? przemol -- http://m

Re: fileinput.input, readlines and ...

2009-06-24 Thread Private Private
On Jun 24, 11:00 pm, Peter Otten <__pete...@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(),

Re: fileinput.input, readlines and ...

2009-06-24 Thread Scott David Daniels
Private Private wrote: On Jun 24, 1:32 pm, Peter Otten <__pete...@web.de> 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() Name

Re: fileinput.input, readlines and ...

2009-06-24 Thread Peter Otten
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 defin

Re: fileinput.input, readlines and ...

2009-06-24 Thread Scott David Daniels
Peter Otten wrote: Scott David Daniels wrote: Peter Otten wrote: with open(filename) as instream: lines = (line.strip() for line in lines) lookup = dict(zip(lines, lines)) Little bit of a fluff-up here. Sorry, it should have been with open(filename) as instream: lines = (lin

Re: fileinput.input, readlines and ...

2009-06-24 Thread Private Private
On Jun 24, 1:32 pm, Peter Otten <__pete...@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 > > ... > >

Re: fileinput.input, readlines and ...

2009-06-24 Thread Peter Otten
Scott David Daniels wrote: > Peter Otten wrote: >> with open(filename) as instream: >> lines = (line.strip() for line in lines) >> lookup = dict(zip(lines, lines)) > Little bit of a fluff-up here. Sorry, it should have been with open(filename) as instream: lines = (line.strip()

Re: fileinput.input, readlines and ...

2009-06-24 Thread Scott David Daniels
Peter Otten wrote: ... If you need more than a few name value pairs it pays to put the data in a dictionary first: # assuming that values always consist of a single line with open(filename) as instream: lines = (line.strip() for line in lines) lookup = dict(zip(lines, lines)) print lo

Re: fileinput.input, readlines and ...

2009-06-24 Thread Peter Otten
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

fileinput.input, readlines and ...

2009-06-24 Thread Przemyslaw Bak
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 fileinpu