Skip to content

the example for "custom node class" doesn´t work, additional parameters are not recognized #240

@emxfer

Description

@emxfer

Trying to implement a more complex node, when using the example as a start point i got this error:

 file_tree.create_node("Large File", "big_file", size=50*1024*1024, `file_type="video")

TypeError: Tree.create_node() got an unexpected keyword argument 'size'

this is the code i used

from treelib import Node, Tree

class FileNode(Node):
    def __init__(self, tag, identifier=None, size=0, file_type="unknown"):
        super().__init__(tag, identifier)
        self.size = size
        self.file_type = file_type

    @property
    def size_mb(self):
        return self.size / (1024 * 1024)

    def is_large_file(self):
        return self.size > 10 * 1024 * 1024  # 10MB

# Use custom node class
file_tree = Tree(node_class=FileNode)
file_tree.create_node("Large File", "big_file", size=50*1024*1024, file_type="video")

file_tree.show()

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions