MCPcopy
hub / github.com/csev/py4e / replace_with

Method replace_with

code3/bs4/element.py:220–233  ·  view source on GitHub ↗
(self, replace_with)

Source from the content-addressed store, hash-verified

218 previousSibling = _alias("previous_sibling") # BS3
219
220 def replace_with(self, replace_with):
221 if not self.parent:
222 raise ValueError(
223 "Cannot replace one element with another when the"
224 "element to be replaced is not part of a tree.")
225 if replace_with is self:
226 return
227 if replace_with is self.parent:
228 raise ValueError("Cannot replace a Tag with its parent.")
229 old_parent = self.parent
230 my_index = self.parent.index(self)
231 self.extract()
232 old_parent.insert(my_index, replace_with)
233 return self
234 replaceWith = replace_with # BS3
235
236 def unwrap(self):

Callers 10

wrapMethod · 0.95
test_replace_withMethod · 0.45
appendChildMethod · 0.45
insertBeforeMethod · 0.45

Calls 3

extractMethod · 0.95
indexMethod · 0.45
insertMethod · 0.45