Blocking readline() Call?

Jp Calderone exarkun at intarweb.us
Mon Nov 10 15:15:02 EST 2003


On Mon, Nov 10, 2003 at 11:59:42AM -0800, Scott Brady Drummonds wrote:
> Hi, everyone,
> 
> I'm just figuring Python out but have become stalled with the following
> snippit of code:  For some reason, the program stalls after the "read line:
> x" for the last line.  The 'done reading cycle map' message is never
> generated:
> 
>   while 1:
>     line = file.readline()
>     if line == '':
>       continue

  I think you mean "break" here, not "continue".


>     data = line.strip().split(':')
>     cycleMap[int(data[0])] = int(data[1])
>     i = i + 1
>     print ('read line %d' % i)
>   file.close()
>   print ('done reading cycle map')


  Another way to write this loop would be:

    for line in file:
        ...

  Jp





More information about the Python-list mailing list