Python equivalent of Perl's Input Record Separator ?

Rich rich at mchsi.com
Wed Feb 12 13:34:56 EST 2003


Thanks everyone...

The files are about 150mb each (Exchange tracking logs)..

Rich.

"Alex Martelli" <aleax at aleax.it> wrote in message
news:WHr2a.227612$AA2.8862505 at news2.tin.it...
> remco boerma wrote:
>
> >> I have a large file with records ending in ox0a 0x0a, the records also
> >> contain \n's
> >
> > If the file is not to long you could use:
> >
> > f  = file('filename')
> > sep = chr(0x0a) *2
> > records = file.read().split(sep)
> > f.close
>
> Error: use f.close()
>
> the trailing parenteses are needed.
>
> > print 'File has', len(records),'records'
>
> Sure, but "large file" normally means one that won't fit comfortably
> in memory, and here you'd need it to fit comfortably in HALF of
> memory -- that's why I gave a generator-based solution, with low
> memory consumption, not tied to the file size but only to the maximum
> size of each record.
>
>
> Alex
>






More information about the Python-list mailing list