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