On Fri, 9 Sep 2011 12:31:49 -0700 (PDT)
mdb <[email protected]> wrote:
> I assumed pyhton has an easy way to 'unconsume'
> a generator. I guess not.
most of the time changing
for i in makes_iterator():
to
reusable = list(makes_iterator())
for i in reusable:
...
<do something else with reusable>
will work, but it's not guaranteed because of cases like
p.self_and_subtree(), where each call of .next() returns the same
object, with changes to its instance variables. In cases like that you
need something like
reusable = [i.copy() for i in p.self_and_subtree()]
etc. as above
In theory the iterator might be doing something completely
unrepeatable, like having a robot drill holes in something and
reporting the time taken for each hole. You could store a
list of the times reported, but the point is the iterator could be
doing anything, and not everything is repeatable. Of course iterating
over a Leo tree without changing it is repeatable.
Cheers -Terry
--
You received this message because you are subscribed to the Google Groups
"leo-editor" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/leo-editor?hl=en.