File tree Expand file tree Collapse file tree 2 files changed +38
-0
lines changed
Expand file tree Collapse file tree 2 files changed +38
-0
lines changed Original file line number Diff line number Diff line change 1+ # Working with Classes
2+
3+ Custom classes can be assigned to Node as ` data ` attribute, or any other attribute name.
4+
5+ ``` python
6+ from bigtree import Node
7+
8+
9+ class Folder :
10+ def __init__ (self , name : str ):
11+ self .name = name
12+
13+ def __str__ (self ):
14+ return f " Folder< { self .name} > "
15+
16+ class File :
17+ def __init__ (self , name : str ):
18+ self .name = name
19+
20+ def __str__ (self ):
21+ return f " File< { self .name} > "
22+
23+ folder_documents = Node(" My Documents" , data = Folder(" Documents" ))
24+ file_photo1 = Node(" photo1.jpg" , data = File(" photo.jpg" ))
25+ file_photo2 = Node(" photo2.jpg" , data = File(" photo.jpg" ))
26+ folder_documents.children = [file_photo1, file_photo2]
27+
28+ folder_documents.show()
29+ # My Documents
30+ # ├── photo1.jpg
31+ # └── photo2.jpg
32+
33+ folder_documents.show(alias = " data" )
34+ # Folder<Documents>
35+ # ├── File<photo.jpg>
36+ # └── File<photo.jpg>
37+ ```
Original file line number Diff line number Diff line change 5959 - others/nodes.md
6060 - others/merging_trees.md
6161 - others/weighted_trees.md
62+ - others/work_with_classes.md
6263
6364theme :
6465 name : material
You can’t perform that action at this time.
0 commit comments