当前位置: 移动技术网 > IT编程>脚本编程>Python > python解析yaml文件过程详解

python解析yaml文件过程详解

2019年09月09日  | 移动技术网IT编程  | 我要评论

如皋车祸,backtrack中文网,名门剩女

yaml语法规则:

下载pyyaml:

解压安装:

python setup.py install

1.新建test.yaml文件,内容如下:

name: tom smith
age: 37
spouse:
  name: jane smith
  age: 25
children:
 - name: jimmy smith
  age: 15
 - name1: jenny smith
  age1: 12

2.创建python文件test.py,内容如下:

#!/usr/bin/python
# -*- coding: utf-8 -*-
import yaml
f = open('test.yaml')
x = yaml.load(f)
print x

3.运行python test.py 结果如下:

{'age': 37, 'spouse': {'age': 25, 'name': 'jane smith'}, 'name': 'tom smith', 'children': [{'age': 15, 'name': 'jimmy smith'}, {'age1': 12, 'name1': 'jenny smith'}]}

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持移动技术网。

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网