"flushing"/demanding generator contents - implications for injection of control
Gabriel Genellina
gagsl-py at yahoo.com.ar
Mon Feb 5 19:47:01 EST 2007
En Mon, 05 Feb 2007 16:47:43 -0300, metaperl <metaperl at gmail.com> escribió:
> For this program:
>
> def reverse(data):
> for index in range(len(data)-1, -1, -1):
> yield data[index]
>
> r = reverse("golf")
>
> for char in r:
> print char
>
>
> I'm wondering if the line:
>
> r = reverse("golf")
>
> "demands" the contents of the function reverse() all at once and if I
> must write
>
> for char in reverse("golf"):
> print char
>
> if I want the results streamed instead of generated complely.
reverse is a generator; it executes one step at a time. That's the whole
point of generators.
--
Gabriel Genellina
More information about the Python-list
mailing list