自动生成报表以显示数据结构,尤其是树
dsr的Python项目详细描述
简介
我打开这个项目是为了通过破解Python的__repr__
函数来显示数据结构。在
安装
pip install dsr
示例
from dsr import BinaryTreeNode, TreeNode
print('BinaryTreeNode:')a=BinaryTreeNode(100)b=BinaryTreeNode(2)c=BinaryTreeNode(0,a,b)d=BinaryTreeNode('a',c,c)a.right=da.left=dprint(d)print('TreeNode:')root=TreeNode('tree',[TreeNode('types',[TreeNode(str),TreeNode(int)]),TreeNode('values',[TreeNode(1),TreeNode(3.1415926),TreeNode(True)]),TreeNode('empty'),2.718281828,'Not TreeNode'])print(root)
双叶树烯醇
^{pr2}$特雷诺德
('tree')
├── ('types')
│ ├── (<class 'str'>)
│ └── (<class 'int'>)
├── ('values')
│ ├── (1)
│ ├── (3.1415926)
│ └── (True)
├── ('empty')
├── 2.718281828
└── 'Not TreeNode'
- 项目
标签: