[Tutor] Readlines

Adam Vardy Adam Vardy <anvardy@roadrunner.nf.net>
Sat Jun 21 15:51:01 2003


Now I'm trying Read(). I have a couple observations, and wonder what
you folks think. Take the code below. I notice that Read() is
apparently incredibly slow! Text appears on screen, cursor slowly
gliding across. Which surprises as it is only reading a byte at a
time. On a Gigahertz machine.

The other thing is I notice this extract does not run corrently. It's
just supposed to print what it reads. And a part to pause for a
moment, after its printed many lines. (Thought that would be
necessary!)

You'll probably notice the error quicker than I have. I was just
wondering, how can you prevent errors. Suppose its just too warm in
the summer to pick out things easily. Well, would other ways to
structure your code occur to you that may minimize the liklihood of
such errors?

#
fhand=open(filepath,'r')

while c!='':
    while z!='\n':
        z=fhand.read(1)
        print z,
    ln=ln+1
    c=z
    if ln%100==0:
        print ln
        time.sleep(1)

print "DONE."

-- 
Adam Vardy