YAML syntax for Salt and Python

点点圈 提交于 2019-12-10 19:49:23

问题


What is the diference between this:

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

and This:

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?


回答1:


No, it is just a nested dictionary.

Example

YAML code:

first_level_dict_key:
  second_level_dict_key: value_in_second_level_dict

Results in Python:

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

Explanation from salt docs.

RULE TWO: COLONS

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

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



来源:https://stackoverflow.com/questions/34661209/yaml-syntax-for-salt-and-python

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!