使用yaml来写配置文件,和简单的存储数据使用,简直方便的不要不要的,简单总结下yaml 的基本使用方法
废话不多说,直接上代码,基本就两个文件
test.yaml
user: admin
pwd: 123
job:
- teacher
- nurese
-
test: hell0
n1: 52.10
#输出:{'n1': 52.1}
n2: true
n3: false #不区分大小写
#输出:{'n2': True, 'n3': False}
# None用~表示
n4: ~ #输出:{'n4': None}
n7: !!str true
#输出:{'n7': 'true'}
excel:
title:
- one
- two
- three
data:
- #data row 1
- one_one
- one_two
- one_three
- #data row 2
- one_one
- one_two
- one_three
yaml_test.py
# -*- coding:utf-8 -*-
import yaml
def load_yaml(path):
yaml.warnings({
'YAMLLoadWarning':False})
f=open(path,'r',encoding='utf-8') #打开yaml文件
cfg=f.read(