config.yaml文件读入后是一个字典,可用来配置程序中的相关参数;
config_test.yaml文件
'''
yaml文件 注意事项:
不要用Tab,用空格!用空格!用空格!
'''
name: Tom Smith
age: 37
spouse:
name: Jane Smith
age: 25
children:
- name: Jimmy Smith
age: 15
- name1: Jenny Smith
age1: 12
#config_test.py
import yaml
file_path = r"E:\pythonwork\helloword\config_test.yaml"
f = open(file_path)
config = yaml.load(f)
print type(config)
print config
print config['age']
print config['children']
print config['children'][0]['age']
运行结果: