Skip to content Skip to sidebar Skip to footer

Difference Between `attrib` And `extra` Arguments Of Xml.etree.elementtree.element(tag, Attrib={}, **extra)

Both attrib and extra arguments of xml.etree.ElementTree.Element(tag, attrib={}, **extra) could be used to set element attributes, except attrib should be given as a dictionary and

Solution 1:

Look at the source, they're merged together:

attrib.update(extra)

https://hg.python.org/cpython/file/tip/Lib/xml/etree/ElementTree.py#l172

It's been there since ElementTree was a third party library supporting Python 1.5.2.

One would imagine that it's there for convenience, since it may be quite common to have a dictionary of attributes from somewhere, but it should also be ergonomic to write a literal function call with some attribute names, so neither case requires extra punctuation.

Post a Comment for "Difference Between `attrib` And `extra` Arguments Of Xml.etree.elementtree.element(tag, Attrib={}, **extra)"