Quick Start¶
Create a Simplest Tree¶
You can create a simplest tree like this
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | from treevalue import FastTreeValue t = FastTreeValue({ 'a': 1, 'b': 2.3, 'x': { 'c': 'str', 'd': [1, 2, None], 'e': b'bytes', } }) if __name__ == '__main__': print(t) |
A tree value object with the following structure will be created
The output of the code above should be
1 2 3 4 5 6 7 | <FastTreeValue 0x7f61c4ad1b20> ├── 'a' --> 1 ├── 'b' --> 2.3 └── 'x' --> <FastTreeValue 0x7f61c4b53ee0> ├── 'c' --> 'str' ├── 'd' --> [1, 2, None] └── 'e' --> b'bytes' |
Create a Slightly Complex Tree¶
You can easily create a tree value object which is slightly complex, based on FastTreeValue
.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | from treevalue import FastTreeValue t1 = FastTreeValue({'a': 's1', 'b': 2, 'x': {'c': 3, 'd': [1, 2]}}) t2 = FastTreeValue({'a': 'str11', 'b': 2, 'x': {'c': 33, 'd': t1.x.d}}) t3 = FastTreeValue({'t1': t1, 't2': t2, 'sum': t1 + t2}) if __name__ == '__main__': print('t1:') print(t1) print('t2:') print(t2) print('t3:') print(t3) |
The result should be
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 | t1: <FastTreeValue 0x7fad38736b20> ├── 'a' --> 's1' ├── 'b' --> 2 └── 'x' --> <FastTreeValue 0x7fad38793ee0> ├── 'c' --> 3 └── 'd' --> [1, 2] t2: <FastTreeValue 0x7fad3832df70> ├── 'a' --> 'str11' ├── 'b' --> 2 └── 'x' --> <FastTreeValue 0x7fad3873fa30> ├── 'c' --> 33 └── 'd' --> [1, 2] t3: <FastTreeValue 0x7fad387ab1c0> ├── 'sum' --> <FastTreeValue 0x7fad3832dee0> │ ├── 'a' --> 's1str11' │ ├── 'b' --> 4 │ └── 'x' --> <FastTreeValue 0x7fad3832deb0> │ ├── 'c' --> 36 │ └── 'd' --> [1, 2, 1, 2] ├── 't1' --> <FastTreeValue 0x7fad38736b20> │ ├── 'a' --> 's1' │ ├── 'b' --> 2 │ └── 'x' --> <FastTreeValue 0x7fad38793ee0> │ ├── 'c' --> 3 │ └── 'd' --> [1, 2] └── 't2' --> <FastTreeValue 0x7fad3832df70> ├── 'a' --> 'str11' ├── 'b' --> 2 └── 'x' --> <FastTreeValue 0x7fad3873fa30> ├── 'c' --> 33 └── 'd' --> [1, 2] |
Three simple treevalue structures are created. Then save the code above to demo.py
, and then input this shell command in your terminal.
1 | treevalue graph -t 'complex_demo.*' -c 'bgcolor=#ffffff00' -d list -o complex_demo.dat.svg |
A graph named demo.dat.svg
will be generated, like this.
Now you are successfully started.