FIFO problems

Steve Holden sholden at holdenweb.com
Thu Sep 11 19:50:54 CEST 2003


"Duncan Booth" <duncan at NOSPAMrcp.co.uk> wrote in message
news:Xns93F388B7855duncanrcpcouk at 127.0.0.1...
> "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.
>
:-) Well, I can only remind myself that "the person who never made a mistake
never made anything".

> Here's my (equally untested) alternative:
>
> for line in serverIn:
>     line = line[:-1]
>     if line == "bla":
>         do something incredibly interesting
>     else:
>         print line
>

Unfortunately this doesn't include the end-of-file test that caused me to
write my original incorrect code. If it did, however, I'm sure it would work
;-)

regards
-- 
Steve Holden                                  http://www.holdenweb.com/
Python Web Programming                 http://pydish.holdenweb.com/pwp/







More information about the Python-list mailing list