On Thu, 21 Jun 2012 14:20:23 +0200 Thomas Rachel <nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa...@spamschutz.glglgl.de> wrote:
> Am 21.06.2012 13:25 schrieb John O'Hagan: > > > But what about a generator? > > Yes, but... > > > def some_func(): > > arg = big_calculation() > > while 1: > > i = yield > > (do_something with arg and i) > > > > some_gen = some_func() > > some_gen.send(None) > > for i in lots_of_items: > > some_gen.send(i) > > rather > > def some_func(it): > arg = big_calculation() > for i in it: > do_something(arg, i) > > some_func(lots_of_items) > Ah yes, this demonstrates that my examples were too simple to show what I'm trying to do. In my real code, several functions take the elements from an iterator, so I can't pass the whole iterator to each one. I have a feeling there is some bad factoring in my real code which will disappear if I manage to provide a clear example, which I'll now endevour to do. Thanks for the reply. -- John -- http://mail.python.org/mailman/listinfo/python-list