File reading using delimiters

DavidW Blaschke dwblas at yahoo.com
Mon Jun 9 15:55:12 EDT 2003


As posted in the other reply, read all of the data at
once and then parse it.  If the file is too large, you
can read it one byte at a time until you find the
delimiter with file.read( 1 ).  Don't know how that
will affect performance though.

> --- In python-list at yahoogroups.com, Peter Hansen
> <peter at e...> wrote:
> > Kylotan wrote:
> > > 
> > > All the examples of reading files in Python seem
> to concern 
> reading a
> > > line at a time. But this is not much good to me
> as I want to be 
> able
> > > to read up to arbitrary delimiters without
> worrying about how many
> > > lines I'm spanning. With my rudimentary Python
> knowledge I'm 
> having to
> > > read in multiple lines, concatenate them, search
> for the 
> delimiter,
> > > split the result if necessary, and carry forward
> whatever was 
> after
> > > the delimiter to the next operation. Is there a
> better way of 
> reading
> > > until a certain character is encountered, and no
> more?
> > 
> > You could always avoid readline() and use just
> read() to get either
> > all the data (for files under a few tens of
> megabytes) or read(x) 
> > where x is some block-size, for larger files. 
> Without more 
> information
> > about the nature of the files and the type of
> scanning, I can't
> > help more.
> > 
> > -Peter
> > -- 
> >
> http://mail.python.org/mailman/listinfo/python-list
> 


__________________________________
Do you Yahoo!?
The New Yahoo! Search - Faster. Easier. Bingo.
http://search.yahoo.com





More information about the Python-list mailing list