wasm-demo/demo/ermis-f/python_m/cur/1980

53 lines
1.2 KiB
Plaintext

From: mlh at idt.ntnu.no (Magnus L. Hetland)
Date: 04 May 1999 12:47:41 +0200
Subject: An Iterator Idiom
References: <Pine.SUN.3.95-heb-2.07.990503233102.28895B-100000@sunset.ma.huji.ac.il>
Message-ID: <y0jk8up1582.fsf@vier.idi.ntnu.no>
X-UID: 1980
Moshe Zadka <moshez at math.huji.ac.il> writes:
> Hi!
>
> I've seen the ``How do you do while(<>) in Python? We need assignment
> in conditionals...No we don't...yes we do....while 1 is evil....is
> not...'' thread once more, I decided to do something about it.
>
[...]
>
> How do I use it?
>
> Well, something like
>
> for line in iterator(sys.stdin.readline):
> sys.stdout.write(line)
>
> as well as
>
> for buff in iterator(sys.stdin.read, 1024):
> sys.stdout.write(buff)
Nice -- but it has been done before, by several people. (Myself
included, if I am not mistaken). Check out dejanews. I think I called
it repeat. So:
for line in repeat(sys.stdin.readline):
process(line)
or something is what you should look for.
(I think it was even suggested as a built-in function.)
>
> Should work.
--
Magnus
Lie
Hetland http://arcadia.laiv.org <arcadia at laiv.org>