Marc Tompkins wrote: > though - I think I need to do > > if len(buf) < recLen: > return > > rather than > > if not buf: > return > > I'll have to experiment again to refresh my memory, but I believe I > tried that in one of my first iterations (about a year ago, so I may be > remembering wrong.) If I remember correctly, read() was still returning > a result - but with a size that didn't evaluate to false. As you can > imagine, hilarity ensued when I tried to slice the last record.
Yes, there might be a partial record or a newline or some kind of cruft at the end of the file. If that is the case you will have to guard against yielding short records, too, e.g. rec = buf[ix:ix+recLen] if len(rec) == recLen: yield rec which will make my version about as long as yours I think :-) Kent _______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor