first, second, etc line of text file

Grant Edwards grante at visi.com
Wed Jul 25 16:48:57 EDT 2007


On 2007-07-25, Jeff McNeil <jeff at jmcneil.net> wrote:

> Depending on the size of your file, you can just use
> file.readlines. Note that file.readlines is going to read the
> entire file into memory, so don't use it on your plain-text
> version of War and Peace.

I don't think that would actually be a problem for any recent
machine.  

The Project Gutenberg version of W&P is 3.1MB of text in 67403
lines.  I just did an f.readlines() on it and it was pretty
much instantaneous, and the python interpreter instance that
contains that list of 67403 lines is using a bit less than 8MB
of RAM. An "empty" interpreter uses about 2.7MB. So, doing
f.readlines() on War and Peace requires a little over 5MB of RAM
-- not really much of a concern on any machine that's likely to
be running Python.

-- 
Grant Edwards                   grante             Yow! Now I understand the
                                  at               meaning of "THE MOD SQUAD"!
                               visi.com            



More information about the Python-list mailing list