MCPcopy Index your code
hub / github.com/python/cpython / remove

Method remove

Lib/xml/etree/ElementTree.py:254–274  ·  view source on GitHub ↗

Remove matching subelement. Unlike the find methods, this method compares elements based on identity, NOT ON tag value or contents. To remove subelements by other means, the easiest way is to use a list comprehension to select what elements to keep, and then use sli

(self, subelement)

Source from the content-addressed store, hash-verified

252 raise TypeError('expected an Element, not %s' % type(e).__name__)
253
254 def remove(self, subelement):
255 """Remove matching subelement.
256
257 Unlike the find methods, this method compares elements based on
258 identity, NOT ON tag value or contents. To remove subelements by
259 other means, the easiest way is to use a list comprehension to
260 select what elements to keep, and then use slice assignment to update
261 the parent element.
262
263 ValueError is raised if a matching element could not be found.
264
265 """
266 try:
267 self._children.remove(subelement)
268 except ValueError:
269 # to align the error type with the C implementation
270 if isinstance(subelement, type) or not iselement(subelement):
271 raise TypeError('expected an Element, not %s' %
272 type(subelement).__name__) from None
273 # to align the error message with the C implementation
274 raise ValueError(f"{subelement!r} not in {self!r}") from None
275
276 def find(self, path, namespaces=None):
277 """Find first matching element by tag name or path.

Callers 5

test_simpleopsMethod · 0.95
test_remove_errorsMethod · 0.95
removeChildMethod · 0.45
removeChildMethod · 0.45
_includeFunction · 0.45

Calls 1

iselementFunction · 0.85

Tested by 2

test_simpleopsMethod · 0.76
test_remove_errorsMethod · 0.76