[Tutor] readlinesX
Kalle Svensson
kalle@gnupung.net
Tue, 20 Mar 2001 00:09:24 +0100
Sez Shawhan, Douglas (GEAE, GECC):
> I have been scouting around on the python.org site looking for references
> to readlineX. Where can I find the whole poop on this function?
That would be xreadlines?
There is no good documentation at the moment, but here's what I know:
The below applies to the function xreadlines in the module xreadlines, and
the file object method xreadlines.
It returns a sequence object, much like the list returned by readlines, only
it doesn't read all the lines into memory but reads them "on demand"
(reading ahead a bit for performance, I think).
Thus, it's now possible to do
for line in file.xreadlines(): # formerly file.readlines()
# do stuff with line
without reading the entire file into memory. This does away with
while 1:
line = file.readline()
if not line:
break
# do stuff with line
which is sort of ugly.
The above is IIRC, AFAIK and IMHO.
Peace,
Kalle
--
Email: kalle@gnupung.net | You can tune a filesystem, but you
Web: http://www.gnupung.net/ | can't tune a fish. -- man tunefs(8)
PGP fingerprint: 0C56 B171 8159 327F 1824 F5DE 74D7 80D7 BF3B B1DD
[ Not signed due to lossage. Blame Microsoft Outlook Express. ]