博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
python 读写yaml
阅读量:4045 次
发布时间:2019-05-25

本文共 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/

你可能感兴趣的文章
【剑指offer】q50:树中结点的最近祖先
查看>>
二叉树的非递归遍历
查看>>
【leetcode】Reorder List (python)
查看>>
【leetcode】Linked List Cycle (python)
查看>>
【leetcode】Linked List Cycle (python)
查看>>
【leetcode】Candy(python)
查看>>
【leetcode】Clone Graph(python)
查看>>
【leetcode】Sum Root to leaf Numbers
查看>>
【leetcode】Pascal's Triangle II (python)
查看>>
java自定义容器排序的两种方法
查看>>
如何成为编程高手
查看>>
本科生的编程水平到底有多高
查看>>
AngularJS2中最基本的文件说明
查看>>
从头开始学习jsp(2)——jsp的基本语法
查看>>
使用与或运算完成两个整数的相加
查看>>
备忘:java中的递归
查看>>
DIV/CSS:一个贴在左上角的标签
查看>>
Solr及Spring-Data-Solr入门学习
查看>>
Vue组件
查看>>
python_time模块
查看>>