> But seeing the first > element of the iterator is p, which hasn't changed, the question seemed > moot.
You are right I should just print p.h By trying to extract again from p.self_and_subtree() I was making the problem too hard for myself I also can use Ed's suggestion to use for p2 p.self_and_subtree() in defining the loop. However in one case I am passing the generator of the subtree to a python function that I created and I do not want to consume the generator (need to access it later) in running this function. I will check out itertools. I assumed pyhton has an easy way to 'unconsume' a generator. I guess not. copy() in leo scripts is another issue for p2 in p.copy().self_and_subtree(): gives errors. Can't seem to use .copy() under any circumstances for the generators I created AttributeError: 'generator' object has no attribute 'copy' Might this be intentional ? (to avoid sloppy coding by users) > > > This does not advance p, so you are free later to do whatever you want > > with p. The code creates no unnecessary explicit iter object. > > Finally, the name p2 (rather than px) is a standard coding convention > > that allows more autocompleter completions for "p2.". > > I don't think p.self_and_subtree() advances p either, at least it > didn't appear to just now in a quick test. The OP's issue seemed to be > wanting to access the first element of an iterator after you've > consumed the iterator, which requires copying it to a list or using > itertools.tee or catching the value in iteration 0. In all these cases > the need for p2.copy() could probably bite you. > But seeing the first > element of the iterator is p, which hasn't changed, the question seemed > moot. > > 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.
