Whoops, I now find my second approach doesn't work, so back to the original question, what's the neatest way to remove nodes matching a criteria?
Cheers -Terry On Wed, 18 Jun 2008 15:36:39 -0500 Terry Brown <[EMAIL PROTECTED]> wrote: > > What's the best way do delete nodes? > > I find myself writing this: > > def cmd_PurgeVanishedFiles(c): > """Remove files no longer present, i.e. "*filename*" entries.""" > p = c.currentPosition() > c.beginUpdate() > try: > cull = [child.copy() for child in p.children_iter() > if child.headString().startswith('*')] if cull: > c.setChanged(True) > cull.reverse() > for child in cull: > g.es(child.headString()) > child.doDelete() > finally: > c.endUpdate() > > to remove all the children of a node matching a criteria. > > Is there a better way? > > Ooops, answering my own question: > > def cmd_PurgeVanishedFiles(c): > """Remove files no longer present, i.e. "*filename*" entries.""" > p = c.currentPosition() > c.beginUpdate() > try: > for child in p.children_iter(copy=True): > if child.headString().startswith('*'): > c.setChanged(True) > g.es(child.headString()) > child.doDelete() > finally: > c.endUpdate() > > i.e. use copy=True, and then the above works, it didn't work without > copy=True. Still kind of scares me, feels like the cartoon character > running across the bridge as it disintegrates behind it, but I guess > that's ok. > > 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 leo-editor@googlegroups.com 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 -~----------~----~----~----~------~----~------~--~---