forked from bigjason/datatree
-
Notifications
You must be signed in to change notification settings - Fork 0
/
example.py
28 lines (26 loc) · 805 Bytes
/
example.py
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
from datatree import Tree
if __name__ == '__main__':
tree = Tree()
#tree.instruct('xml', version='1.0')
with tree.node("author") as author:
author.node('name', 'Terry Pratchett')
author.node('genre', 'Fantasy/Comedy')
author.comment("Only 2 books listed")
with author.node('novels', count=2) as novels:
novels.node('novel', 'Small Gods', year=1992)
novels.node('novel', 'The Fifth Elephant', year=1999)
novels.node("novel", "Guards! Guards!", year=1989)
print 'XML:'
print author(pretty=True)
print
print
print 'JSON:'
print author('json', pretty=True)
print
print
print 'YAML:'
print author('yaml')
print
print
print 'Dict:'
print author('dict', pretty_string=True)