FIFO problems

Duncan Booth duncan at NOSPAMrcp.co.uk
Thu Sep 11 08:28:53 EDT 2003


"Steve Holden" <sholden at holdenweb.com> wrote in 
news:tJZ7b.67$o71.53 at news2.central.cox.net:

> There are various ways around this. Since you are talking interactive
> multi-process stuff here it's probably safest to do somehting like the
> following (untested) code:
> 
> while 1:
>     line = serverIn.readline()
>     if not line:
>         break
>     del line[:-1]
>     if line == "bla":
>         do something incredibly interesting
>     else:
>         print line

Untested is right. Your 'del' statement is a little bit too destructive, or 
at least it would be if strings were mutable.

Here's my (equally untested) alternative:

for line in serverIn:
    line = line[:-1]
    if line == "bla":
        do something incredibly interesting
    else:
        print line
    


-- 
Duncan Booth                                             duncan at rcp.co.uk
int month(char *p){return(124864/((p[0]+p[1]-p[2]&0x1f)+1)%12)["\5\x8\3"
"\6\7\xb\1\x9\xa\2\0\4"];} // Who said my code was obscure?




More information about the Python-list mailing list