[Tutor] looking for data in large text file

Alan Gauld alan.gauld@blueyonder.co.uk
Wed Jul 16 04:07:03 2003


> But how do I look for a list in a text file without have to readline
the
> whole file?

First reading even a thousand lines won't take all that long.
However you only need to read as many lines as it takes to get
your list out.

Second, you could store the lists in separate files.

Third you could put a table of contents at the top of the file
giving the byte offset to the start of each list then use seek()
to go there directly - but the maintenance of that will be a lot
of work and not noramally worth it for such relatively short files.

Finally, and the method I would probably use - read the file once at
startup and store the lists in memory somewhere.

Alan G
Author of the Learn to Program web tutor
http://www.freenetpages.co.uk/hp/alan.gauld