[Tutor] little something in the way of file parsing
Tom Jenkins
tjenkins@devis.com
22 Jul 2002 17:23:26 -0400
On Fri, 2002-07-19 at 16:36, Sean 'Shaleh' Perry wrote:
>
> On 19-Jul-2002 Erik Price wrote:
> > On Friday, July 19, 2002, at 02:49 PM, Sean 'Shaleh' Perry wrote:
> >
[snip]
> >> # note I use the readline() idiom because there is currently 10
> >> thousand plus
> >> # entries in the file which equates to some 90,000 lines.
> >>
> >> while 1:
> >> line = fd.readline()
> >
> > I assume that this comment means that you use readline() as opposed to
> > readlines() ? In other words, what are you actually saying in this
> > comment (or rather why did you feel the need to clarify why you chose
> > readline() ).
> >
>
> I added this comment for the tutor list. In many intro examples you see:
>
> for line in file.readlines()
> handle(line)
>
> which is great for quicky code. However readlines() returns a list of strings.
> In my case it returns a 100 thousand element list of strings -- memory wasted.
>
To further along Danny's idea of digging into the code...
I have a question as to why xreadlines wouldn't work here? It seems
that this is exactly what xreadlines is for; iterating over a large file
without loading it all into memory at once. Ah, wait xreadlines is only
available for 2.1+, was that it?
--
Tom Jenkins
Development InfoStructure
http://www.devis.com