Tree functions

change_parent(cur, node, new_parent, position=None, auto_position=True)

Move node and its subtree from its current to another parent node. Return updated Node object with new parent set. Raise ValueError if new_parent is inside node s subtree.

Parameters:
  • node (Node or int) –
  • new_parent (Node or int) – Reference to the new parent node
  • position (int) – Position in between siblings. If 0, the node will be inserted at the beginning of the parents children. If -1, the node will be inserted the the end of the parents children. If auto_position is disabled, this is just a value.
  • auto_position (bool) – See Positioning functions.
delete_node(cur, node, auto_position=True)

Delete node and its subtree.

Parameters:
insert_node(cur, parent, properties=None, position=None, auto_position=True)

Create a Node object, insert it into the tree and then return it.

Parameters:
  • parent (Node or int) – Reference to its parent node. If None, this will be the root node.
  • properties (dict) – Inheritable key/value pairs (see Property functions)
  • position (int) – Position in between siblings. If 0, the node will be inserted at the beginning of the parents children. If -1, the node will be inserted the the end of the parents children. If auto_position is disabled, this is just a value.
  • auto_position (bool) – See Positioning functions
print_tree(cur, start_node=None, indent=' ', _level=0)

Print tree to stdout.

Parameters:
  • start_node (int, Node, NodaData or None) – Starting point for tree output. If None, start at root node.
  • indent (str) – String to print per level (default: ‘ ‘)