yaml

相對於json更方便編輯,適合用來存放config資訊

# 範例檔案(config.yaml),讀取後視為config_dic(dict)

# key:value
vm-ip: http://123  # config_dic['vm-ip']


# 巢狀dict
server:
  ip: 123  # config_dic['server']['ip']
  user: 456  # config_dic['server']['user']


# list
all-number:  # config_dic['all-number']
    - 1
    - 2
    - 3

# 混著用
test:
  - key1: 1
    key2: 2
    key3: 3

# dict2yaml
with open('data.yml', 'w') as outfile:
    yaml.dump(data, outfile, default_flow_style=False)

Last updated