[FEEDBACK] Is this script efficient...is there a better way?
Bob X
bobx at linuxmail.org
Wed Sep 11 21:09:59 EDT 2002
> 1) readlines() loads the entire file into a list so if you have a 30+ mb file
> you just ate 30+mb of memory. Try using xreadlines() instead, it reads the
> file line by line and is much more memory friendly.
Very cool...I had missed that!
>
> 2) do you expect to find more than one keyword in a particular line? If not
> you could save some iterations by stopping the inner line.find() loop as soon
> as one item is found.
I could but it doesn't matter after the first on a line. How would I
stop it?
> As a final comment you need to be aware that the more keywords you look for
> the slower this will be. However there is not a way to get around that, it
> is just something to keep in mind.
>
Yeah...the keywords vary...I have used as little as 1 to about 150...
More information about the Python-list
mailing list