parsing a long text file for specific text
Jason Orendorff
jason at jorendorff.com
Wed Jan 30 10:40:17 EST 2002
More information about the Python-list mailing list
Wed Jan 30 10:40:17 EST 2002
- Previous message (by thread): parsing a long text file for specific text
- Next message (by thread): How to activate __future__ features in embedded Python?
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
"Jim Ragsdale" <overlord at netdoor.com> wrote: > Before if I have done anything like this, I used a loop to check > to see if it matched a piece of text, but this takes a while. > Is there a better way? You could try mmap. import mmap import re def search(filename, rx): f = open(filename, 'r+') mem = mmap.mmap(f.fileno(), 0) for match in rx.finditer(mem): print match.group(0) mem.close() f.close() This runs significantly faster than for/xreadlines()/search(), and 50% faster than read()/finditer() for my test file. ## Jason Orendorff http://www.jorendorff.com/
- Previous message (by thread): parsing a long text file for specific text
- Next message (by thread): How to activate __future__ features in embedded Python?
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-list mailing list