[ANN] xreadlines patch on sourceforge

Jeff Epler jepler at inetnebr.com
Mon Dec 18 22:41:55 EST 2000


I've just uploaded my "xreadlines" patch to Sourceforge.  You can
retrieve it from the Patch Manager, and it is my hope that it will
be considered for inclusion in Python 2.1.

xreadlines, inspired by xrange, permits a simple 'for' loop to iterate
over the contents of a file without reading the entire file at once.

xreadlines is both a new extension module, as well as an additional
method on file objects.  It includes an entry for the test suite,
as well as a modified 'fileinput' module which has a >2x speed
improvement by using the xreadlines function.

example:

def wc(filename):
	l=w=c=0
	for line in open(filename).xreadlines():
		c=c+len(line)
		w=w+len(line.split())
		l=l+1
	return (l,w,c)


Jeff Epler
jepler at inetnebr.com



More information about the Python-list mailing list