python 的 yaml 操作例子

依赖


rpm -qa | grep PyYAML
PyYAML-3.10-3.1.el6.x86_64

例子代码


#!/usr/bin/python
import os, sys,yaml

fname="index.yaml"

f = open(fname,"r")
x=yaml.load(f)

#print(x)

dist={}

dlist="centos6.x86_64|centos7.x86_64"
arr = dlist.split("|")

for ite in arr:
dist[ite] = {}
dist[ite]['release'] = "{{.gitcount}}.{{.dist}}"
x['distribution'] = dist
#print "\n\n"
#print x
#print "\n"
ret = yaml.dump(x)
print ret

This entry was posted in 运维相关. Bookmark the permalink. Follow any comments here with the RSS feed for this post. Both comments and trackbacks are currently closed.

2 Comments