Salt 和 Python 的 YAML 语法 [英] YAML syntax for Salt and Python

查看:64
本文介绍了Salt 和 Python 的 YAML 语法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这有什么区别:

dic1: 
  - subdict1.1: value11.1
  - subdict1.2: value1.2
  - cubdict1.3: value1.3

还有这个:

dict2:
  subdict2.1: value2.2
  subdict2.1: value2.2
  subdict2.3: value2.3

我知道第一个评估为字典列表.但第二个是什么?不也是字典列表吗?

I know the first one evaluates to a list of dictionaries. but what is the second one? isn't also a list of dictionaries?

推荐答案

不,它只是一个嵌套字典.

示例

YAML 代码:

first_level_dict_key:
  second_level_dict_key: value_in_second_level_dict

结果Python中:

{
    'first_level_dict_key': {
        'second_level_dict_key': 'value_in_second_level_dict'
    }
}

来自 salt docs 的解释.

规则二:冒号

Python 字典当然只是键值对.用户来自其他语言可能将此数据类型识别为散列或关联数组.

Python dictionaries are, of course, simply key-value pairs. Users from other languages may recognize this data type as hashes or associative arrays.

字典键在 YAML 中表示为以 a 结尾的字符串尾随冒号.值由以下任一字符串表示冒号,用空格隔开

Dictionary keys are represented in YAML as strings terminated by a trailing colon. Values are represented by either a string following the colon, separated by a space

这篇关于Salt 和 Python 的 YAML 语法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆