Newbie Question: can this snippet be optimized?

Hedr Hedr
Wed Jun 25 17:08:00 CEST 2003

Hi Pythonians,

The underlying snippet is copied from which is in the XML
package which I am currently using. Cloning nodes seem to take a
considerable amount of time, hence I went looking in the code whether
optimizations could be made. The following snippet contains a for

    def cloneNode(self, deep):
        clone = Node.cloneNode(self, deep)
        clone._attrs = {}
        clone._attrsNS = {}
        for attr in self._attrs.values():
            node = attr.cloneNode(1)
            clone._attrs[] = node
            clone._attrsNS[(node.namespaceURI, node.localName)] = node
            node.ownerElement = clone
        return clone

I just wondered if this could be optimized (mao, array, whatever) and
if so, how? I do not have much experience with Python, hence the

Thanks for suggestions,


More information about the Python-list mailing list