def iterparse ( source , tag , clear = False , events = None ) : for event , elem in ElementTree . iterparse ( source , events = events ) : if elem . tag == tag : yield elem if clear : elem . clear ( )
python elementtree iterparse clear
iterparse variant that supports tag parameter ( like lxml ) yields elements and clears nodes after parsing .
def iterparse(source, tag, clear=False, events=None):
    """
    iterparse variant that supports 'tag' parameter (like lxml),
    yields elements and clears nodes after parsing.
    """
    for event, elem in ElementTree.iterparse(source, events=events):
        if elem.tag == tag:
            yield elem
        if clear:
            elem.clear()