Looping [was Re: Python and the need for speed]

Paul Rubin no.email at nospam.invalid
Wed Jun 21 03:49:50 EDT 2017


Chris Angelico <rosuav at gmail.com> writes:
> while True:
>     c = sys.stdin.read(1)
>     if not c: break
>     if c.isprintable(): text += c
>     elif c == "\x08": text = text[:-1]
>     # etc
> Can you write _that_ as a do-while?

I prefer to write that sort of thing with iterators:

 for c in iter(lambda: sys.stdin.read(1), ''):
     if c.isprintable(): text.append(c)
     elif c == '\x08': text.pop()
     ...



More information about the Python-list mailing list