split large file by string/regex

Martin Dieringer dieringe at zedat.fu-berlin.de
Mon Nov 22 14:48:16 EST 2004


"Denis S. Otkidach" <ods at strana.ru> writes:

> On Mon, 22 Nov 2004 08:53:02 -0500
> Steve Holden <steve at holdenweb.com> wrote:
>
>> > I am trying to split a file by a fixed string.
>> > The file is too large to just read it into a string and split this.
>> > I could probably use a lexer but there maybe anything more simple?
>> > thanks
>> > m.
>> 
>> Depends on your definition of "simple", I suppose. The problem with 
>> *not* using a lexer is that you'd have to examine the file in a sequence 
>> of overlapping chunks to make sure that a regex could pick up all 
>
> re module works fine with mmap-ed file, so no need to read it into memory.
>

thank you, this is the solution! 
Now I can mmap.find all locations and then read the chunks them via
file.seek and file.read

m.



More information about the Python-list mailing list