NodeWithChildren#
Qualified name: rsm.nodes.NodeWithChildren
- class rsm.nodes.NodeWithChildren(**kwargs)[source]#
Bases:
Node
A
Node
that may have children Nodes.Methods
Add a child or children after all current children.
Remove all children.
Add a child or children before all current children.
Remove child.
Attributes
Tuple with this Node's children.
- append(child)[source]#
Add a child or children after all current children.
- Parameters:
child (Union[Node, Iterable[Node]]) – Node or iterable or nodes to append.
- Returns:
self
- Raises:
RSMNodeError – When attempting to add as a child a node that already has a parent.
- Return type:
See also
Examples
Append one or many children.
>>> p, t1, t2, t3 = nodes.Paragraph(), nodes.Text("one"), nodes.Text("two"), nodes.Text("three") >>> p.append(t1) >>> p.append([t2, t3]) >>> p.children (Text("one"), Text("two"), Text("three"))
Calls can be chained.
>>> p, t1, t2, t3 = nodes.Paragraph(), nodes.Text("one"), nodes.Text("two"), nodes.Text("three") >>> p.append(t1).append([t2, t3]) >>> p.children (Text("one"), Text("two"), Text("three"))
Will raise when trying to append a node that already has a parent.
>>> p2 = nodes.Paragraph() >>> p2.append(t1) Traceback (most recent call last): rsm.nodes.RSMNodeError: Attempting to append child to a new parent
This is the case even when appending to the same parent.
>>> t4 = nodes.Text("four") >>> p2.append(t4) >>> p2.append(t4) Traceback (most recent call last): rsm.nodes.RSMNodeError: Attempting to append child to a new parent
- property children: tuple[rsm.nodes.Node, ...][source]#
Tuple with this Node’s children.