import tree the_tree = tree.Tree() # create leaf node virus = the_tree.create_leaf('Virus') virus2 = the_tree.create_leaf('Worm') # create child leaf test = virus.create_child_leaf('Test') # create test items inside of 'test' leaf v1 = test.create_child_leaf('a') v2 = test.create_child_leaf('b') v3 = test.create_child_leaf('c') v4 = test.create_child_leaf('884') def walk_cb(node): ident = '' # Walk the parents to figure out current tree depth # and how many parent_list = [] parent = node.parent parent_count = 0 while parent is not None: if parent.item is not None: parent_list.append(parent.item) parent_count += 1 parent = parent.parent #for item in reversed(parent_list): # ident += f'{item}.' if node.item is not None: ident += node.item else: ident = '[root]' tab = '' for i in range(0, parent_count): tab += '\t' print(f"{tab}{ident}") the_tree.walk(walk_cb)