passing parameters to generators ?

Jan Samohyl asgard at hellnet.cz
Sun Nov 4 13:50:10 CET 2001


Hello, 
I would like to pass different parameters to a generator while it's generating, is there some simple way to do that?
I want to write a synchronous server, that would go through all the active connections and when the client response is 
available, it would call a generator with the client response, and resume the conversation with the client exactly at the
point it yielded out to let other talk. I think it would be very cool to do it this way, but unfortunately, current generator
implementation doesn't allow to do it that simply. Why is a function with yield *always* a generator factory? Why it isn't
simply the generator, and generator factory or iterator would be done as a function factory returning generator next()? And
when you would call generator again with different parameters, they would be different inside the generator (but the locals
would stay the same and you would enter behind the last yield statement).

Regards
Jan Samohyl




More information about the Python-list mailing list