> def counter(start_at=0):
> count = start_at
> while True:
> val = (yield count)
A generator can accept a value from the consumer. So, If I have a
counter:
c = counter()
I can send it a value:
c.send(9)
> if val is not None:
> count = val
The generato
Hi,
There is a great set of slides on this topic
available here: http://www.dabeaz.com/generators/
They explain this concept quite well and
walk you through everything you need to
know about generators and how powerful
they can be.
Please read it.
cheers
James
On 8/27/08, Hussein B <[EMAIL PRO
Hussein B <[EMAIL PROTECTED]> writes:
> This is an example of a generator function [using coroutine
> behaviour]:
[…]
> I'm not able to understand how this generator function is working,
> would you please me (what happens when calling next/send)?
The behaviour you're seeing was introduced in PE
Hey,
This is an example of a generator function:
=
def counter(start_at=0):
count = start_at
while True:
val = (yield count)
if val is not None:
count = val
else:
count += 1
==
>>> count = counter(5)
>>> count.next()
5
>>> count.send(9