Ideas about enhancements to fileobjects

Tracy Tims (tracy@gold.sni.ca)
Fri, 19 Nov 1993 16:02:55 -0500

I seem to be using python to do a lot of file scanning.
Anyway, I want my file scanning programs to be fast and able to produce
useful error messages, so I whipped up a pseudo-subclass of fileobject
(this means I'm prototyping in python) that gives me line-oriented input
useful for line-by-line file scanning.

I added two attributes: a current line number and the file name, that make
it much easier for parsers to produce useful error messages (yeah, you can
write a single parser that keeps track of line numbers, but wait until you
try to write a parser class), and I added a number of methods for
looking ahead at lines in the file.

f.peekline() - peek the next unpeeked line
f.peeklinen() - peek the nth unread line
f.peekreset() - make all unread lines unpeeked

This stuff has made it very much easier for me to parse line-oriented input,
but psuedo-classes are too slow, so I'm planning to reimplement these methods
on C for fileobjects, which is where I think they belong.

Anyone else interested? Guido?

Tracy Tims
tracy@sni.ca