本文共 739 字,大约阅读时间需要 2 分钟。
[url]http://mikkel.elmholdt.dk/?p=4[/url] 1. install pyyaml: ([url]http://pyyaml.org/wiki/PyYAMLDocumentation[/url]) 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()
转载地址:http://owuci.baihongyu.com/