Re: [Tutor] Searching in a file

2010-01-15 Thread Dave Angel
Paul Melvin wrote: Hi, Thanks very much to all your suggestions, I am looking into the suggestions of Hugo and Alan. The file is not very big, only 700KB (~2 lines), which I think should be fine to be loaded into memory? I have two further questions though please, the lines are like this:

Re: [Tutor] Searching in a file

2010-01-15 Thread Kent Johnson
On Fri, Jan 15, 2010 at 4:24 AM, Paul Melvin wrote: > Hi, > > Thanks very much to all your suggestions, I am looking into the suggestions > of Hugo and Alan. > > The file is not very big, only 700KB (~2 lines), which I think should be > fine to be loaded into memory? > > I have two further que

[Tutor] Searching in a file

2010-01-15 Thread Paul Melvin
Hi, Thanks very much to all your suggestions, I am looking into the suggestions of Hugo and Alan. The file is not very big, only 700KB (~2 lines), which I think should be fine to be loaded into memory? I have two further questions though please, the lines are like this:

Re: [Tutor] Searching in a file

2010-01-14 Thread Lie Ryan
On 01/14/10 10:29, Hugo Arts wrote: > On Thu, Jan 14, 2010 at 12:05 AM, Alan Gauld > wrote: >> > >> > I prefer the next() approach. > Rightfully so. IMO, The while loop with readline is basically the C > version of that, for the poor people who don't have iterators. I would often prefer while lo

Re: [Tutor] Searching in a file

2010-01-14 Thread Alan Gauld
"spir" wrote But a third option is to use a split and apply it to the whole file as a string thereby breaking the file into as many chunks as start with a line containing 'NEW'... Why not simply a regex pattern starting with "NEW" and ending with '\n'? Because I understood the OP had to e

Re: [Tutor] Searching in a file

2010-01-14 Thread spir
On Wed, 13 Jan 2010 23:05:11 - "Alan Gauld" wrote: > But a third option is to use a split and apply it to the whole file as > a string thereby breaking the file into as many chunks as start with > a line containing 'NEW'... Why not simply a regex pattern starting with "NEW" and ending with '

Re: [Tutor] Searching in a file

2010-01-13 Thread Hugo Arts
On Thu, Jan 14, 2010 at 12:05 AM, Alan Gauld wrote: > > I prefer the next() approach. Rightfully so. IMO, The while loop with readline is basically the C version of that, for the poor people who don't have iterators. > But a third option is to use a split and apply it to the whole file as > a st

Re: [Tutor] Searching in a file

2010-01-13 Thread Alan Gauld
"Hugo Arts" wrote the most obvious answer would be to take a look at the 'next()' function, that should solve this immediate problem. This would be nmy advice too, but you need to get an explicit iterator to use it. it = open(.) for line in it: if 'NEW' in line: ln = it.next

Re: [Tutor] Searching in a file

2010-01-13 Thread Hugo Arts
On Wed, Jan 13, 2010 at 6:49 PM, Paul Melvin wrote: > Hi, > > I have a file generated from a webpage. > > I want to search that file for a specific keyword, in my case 'NEW'. > > Once I have found that keyword I want to retrieve information below it, e.g. > web link, size of file etc. > > When I h

Re: [Tutor] Searching in a file

2010-01-13 Thread Emile van Sebille
On 1/13/2010 9:49 AM Paul Melvin said... Hi, I have a file generated from a webpage. I want to search that file for a specific keyword, in my case 'NEW'. Once I have found that keyword I want to retrieve information below it, e.g. web link, size of file etc. When I have this information I mov

Re: [Tutor] Searching in a file

2010-01-13 Thread wesley chun
> I have a file generated from a webpage. > I want to search that file for a specific keyword, in my case 'NEW'. > Once I have found that keyword I want to retrieve information below it, e.g. > web link, size of file etc. > When I have this information I move off until I find another 'NEW' and the

[Tutor] Searching in a file

2010-01-13 Thread Paul Melvin
Hi, I have a file generated from a webpage. I want to search that file for a specific keyword, in my case 'NEW'. Once I have found that keyword I want to retrieve information below it, e.g. web link, size of file etc. When I have this information I move off until I find another 'NEW' and the pr