Re: python vs. grep

2008-05-13 Thread Ricardo Aráoz
Ville M. Vainio wrote: Ricardo Aráoz <[EMAIL PROTECTED]> writes: The easy/simple (too easy/simple?) way I see out of it is to read THE WHOLE file into memory and don't worry. But what if the file is too The easiest and simplest approach is often the best with Python. Keep forgetting that!

Re: python vs. grep

2008-05-12 Thread Ville M. Vainio
Ricardo Aráoz <[EMAIL PROTECTED]> writes: > The easy/simple (too easy/simple?) way I see out of it is to read THE > WHOLE file into memory and don't worry. But what if the file is too The easiest and simplest approach is often the best with Python. Reading in the whole file is rarely too heavy, a

Re: python vs. grep

2008-05-12 Thread Kam-Hung Soh
On Tue, 13 May 2008 00:03:08 +1000, Ricardo Aráoz <[EMAIL PROTECTED]> wrote: Ville Vainio wrote: On May 8, 8:11 pm, Ricardo Aráoz <[EMAIL PROTECTED]> wrote: All these examples assume your regular expression will not span multiple lines, but this can easily be the case. How would you proce

Re: python vs. grep

2008-05-12 Thread Ricardo Aráoz
Ville Vainio wrote: On May 8, 8:11 pm, Ricardo Aráoz <[EMAIL PROTECTED]> wrote: All these examples assume your regular expression will not span multiple lines, but this can easily be the case. How would you process the file with regular expressions that span multiple lines? re.findall/ findit

Re: python vs. grep

2008-05-09 Thread Ville Vainio
On May 8, 8:11 pm, Ricardo Aráoz <[EMAIL PROTECTED]> wrote: > All these examples assume your regular expression will not span multiple > lines, but this can easily be the case. How would you process the file > with regular expressions that span multiple lines? re.findall/ finditer, as I said earl

Re: python vs. grep

2008-05-08 Thread Ricardo Aráoz
Anton Slesarev wrote: I try to save my time not cpu cycles) I've got file which I really need to parse: -rw-rw-r-- 1 xxx xxx 3381564736 May 7 09:29 bigfile That's my results: $ time grep "python" bigfile | wc -l 2470 real0m4.744s user0m2.441s sys 0m2.307s And python scrip

Re: python vs. grep

2008-05-08 Thread Robert Kern
Alan Isaac wrote: Anton Slesarev wrote: I've read great paper about generators: http://www.dabeaz.com/generators/index.html Author say that it's easy to write analog of common linux tools such as awk,grep etc. He say that performance could be even better. But I have some problem with writing

Re: python vs. grep

2008-05-08 Thread Alan Isaac
Anton Slesarev wrote: I've read great paper about generators: http://www.dabeaz.com/generators/index.html Author say that it's easy to write analog of common linux tools such as awk,grep etc. He say that performance could be even better. But I have some problem with writing performance grep an

Re: python vs. grep

2008-05-07 Thread Anton Slesarev
On May 7, 7:22 pm, Pop User <[EMAIL PROTECTED]> wrote: > Anton Slesarev wrote: > > > But I have some problem with writing performance grep analog. > > I don't think you can ever catch grep. Searching is its only purpose in > life and its very good at it. You may be able to come closer, this > thr

Re: python vs. grep

2008-05-07 Thread Pop User
Anton Slesarev wrote: But I have some problem with writing performance grep analog. I don't think you can ever catch grep. Searching is its only purpose in life and its very good at it. You may be able to come closer, this thread relates. http://groups.google.com/group/comp.lang.python/

Re: python vs. grep

2008-05-07 Thread Ville Vainio
On May 6, 10:42 pm, Anton Slesarev <[EMAIL PROTECTED]> wrote: > flines = (line for line in f if pat.search(line)) What about re.findall() / re.finditer() for the whole file contents? -- http://mail.python.org/mailman/listinfo/python-list

Re: python vs. grep

2008-05-07 Thread Anton Slesarev
I try to save my time not cpu cycles) I've got file which I really need to parse: -rw-rw-r-- 1 xxx xxx 3381564736 May 7 09:29 bigfile That's my results: $ time grep "python" bigfile | wc -l 2470 real0m4.744s user0m2.441s sys 0m2.307s And python scripts: import sys if len(

Re: python vs. grep

2008-05-06 Thread Wojciech Walczak
2008/5/6, Anton Slesarev <[EMAIL PROTECTED]>: > But I have some problem with writing performance grep analog. [...] > Python code 3-4 times slower on windows. And as I remember on linux > the same situation... > > Buffering in open even increase time. > > Is it possible to increase file readin

Re: python vs. grep

2008-05-06 Thread Arnaud Delobelle
Anton Slesarev <[EMAIL PROTECTED]> writes: > f = open("bigfile",'r') > > flines = (line for line in f if pat.search(line)) > c=0 > for x in flines: > c+=1 > print c It would be simpler (and probably faster) not to use a generator expression: search = re.compile('sometext').search c = 0 for

Re: python vs. grep

2008-05-06 Thread Ian Kelly
On Tue, May 6, 2008 at 1:42 PM, Anton Slesarev <[EMAIL PROTECTED]> wrote: > Is it possible to increase file reading performance? Dunno about that, but this part: > flines = (line for line in f if pat.search(line)) > c=0 > for x in flines: > c+=1 > print c could be rewritten as just: pr

python vs. grep

2008-05-06 Thread Anton Slesarev
I've read great paper about generators: http://www.dabeaz.com/generators/index.html Author say that it's easy to write analog of common linux tools such as awk,grep etc. He say that performance could be even better. But I have some problem with writing performance grep analog. It's my script: