码迷,mamicode.com
首页 > 其他好文 > 详细

yaml 配置

时间:2018-08-05 14:14:32      阅读:869      评论:0      收藏:0      [点我收藏+]

标签:code   ref   相互   并且   name   多少   csdn   格式   识别   

yaml文件的作用

  • yaml是一种直观的能够被电脑识别的的数据序列化格式,容易被人类阅读,并且容易和脚本语言交互。

    yaml的语法规则

  • 字母大小写敏感;
  • 通过缩进来表示层级关系,同层级元素需左对齐,且缩进的空格数多少没关系;
  • 缩进时不允许使用Tab,只允许使用空格
  • #表示注释

    yaml支持字典和列表的表示

  • demo.yaml文件显示如下:
    test_list:
    - name
    - age
    - weight
    test_dict:
    name: jack
    age: 18
    通过Python如下语句读取:
import yaml

with open(demo.yaml,‘rb‘) as f:
    config = yaml.load(f)
test_list = config["test_list"]
test_dict = config["tesst_dict"]
  • 其中test_list返回一个list,test_dict返回dict,俩者也可相互组合

参考:https://blog.csdn.net/lmj19851117/article/details/7843486

yaml 配置

标签:code   ref   相互   并且   name   多少   csdn   格式   识别   

原文地址:https://www.cnblogs.com/ronky/p/9231675.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!