python 读写yaml pythonreadyaml
程序员文章站
2024-01-08 16:15:04
...
http://mikkel.elmholdt.dk/?p=4
1. install pyyaml: (http://pyyaml.org/wiki/PyYAMLDocumentation)
1.1 wget http://pyyaml.org/download/pyyaml/PyYAML-3.01.tar.gz
1.2 tar zxvf PyYAML-3.01.tar.gz
1.3 cd PyYAML-3.01 && python setup.py install
1. install pyyaml: (http://pyyaml.org/wiki/PyYAMLDocumentation)
1.1 wget http://pyyaml.org/download/pyyaml/PyYAML-3.01.tar.gz
1.2 tar zxvf PyYAML-3.01.tar.gz
1.3 cd PyYAML-3.01 && python setup.py install
# tree format treeroot: branch1: name: Node 1 branch1-1: name: Node 1-1 branch2: name: Node 2 branch2-1: name: Node 2-1
import yaml f = open('tree.yaml') dataMap = yaml.load(f) f.close() # dataMap: {'treeroot': {'branch1': {'branch1-1': {'name': 'Node 1-1'}, 'name': 'Node 1'}, 'branch2': {'branch2-1': {'name': 'Node 2-1'}, 'name': 'Node 2'}}}
f = open('newtree.yaml', "w") yaml.dump(dataMap, f) f.close()