
I have run into the following problem with removing an element, and I can't figure out whether it's a bug or whether I'm missing something. I want to make a change to an element, depending on the next element, and delete that next element. The change and deletion occur in a function. The main code program like this: if element.getnext() is not None \ and element.getnext().get('rend') == 'superscript': element = processSuperscripts(element, tree, changelog) The function first spells out the change and then orders the deletion; parent = element.getnext().getparent() parent.remove(element.getnext()) This code works the first time, but it doesn't work on successive occasions. I have used a work around where I add a flag to the next element and delete it in a separate loop. Thus my function ends element.getnext().set('n', 'DELETE') and the main program adds the loop: for element in tree.iter(tei + 'w'): if element.get('n') == 'DELETE': parent = element.getparent() parent.remove(element) This works: all instances of the first element are properly changed and all instances of the second element are properly deleted. Is there a way of making the deletion work inside the function without a second "clean-up" loop? Martin Mueller Professor emeritus of English and Classics Northwestern University