[Edu-sig] Teaching about files

Peter Froehlich phf at cs.ucr.edu
Tue Nov 9 00:57:22 CET 2004

Hi all,

On Nov 7, 2004, at 22:09, Danny Yoo wrote:

> On Sun, 7 Nov 2004, Kent Johnson wrote:
>> So my question is, am I missing something here? Is f.read(n) 
>> important?
> [...]
> I try to deemphasize read() and readlines(), as sucking a whole file 
> as a
> list isn't a technique that will scale well with large inputs.

I teach compilers and allow students to write their compilers in 
Python. The data structures they build tend to be *much* larger than 
the actual source file. So however long that source file is, you can 
"suck it in" since you will *surely* fail with any processing if you 
run out of memory for the file already. What I am trying to say is that 
input alone is not really the bottleneck, it's what you do with it.

Also, I prefer read() in this setting as the compiler doesn't care 
about line numbers. It identifies errors as "offsets" in the file, so 
reading line-by-line really does not buy anything.

However, in the end, I agree that the iteration syntax is nice if your 
problem is of the right kind.

Peter H. Froehlich <><><><><><> http://www.cs.ucr.edu/~phf/
OpenPGP: ABC2 9BCC 1445 86E9 4D59  F532 A8B2 BFAE 342B E9D9

More information about the Edu-sig mailing list