yaml文件中格式
- 键值对
name: tome
assword: 123
- 列表
-100
-abc
-
-bb
-cc1
- 混合类型(列表里面有字典)
a: tome
b:
c: 10
d: 20
info:
- 10
- 20
- .引号用法 双引号 单引号
a: hello\nword
b: 'hello\nword' #特殊字符 原格式输出
c:"hello\nword" #转义后输出效果
- 引用变量
#‘&’ 和‘*’用于引用
info: &ccc abc
data:
- *ccc
- sq
- 200
读取Yaml
#####一个Yaml文件中多个不同数据
name: aa
password: bb
—3个‘-’表示分割线隔开
name: cc
password: 123
#########读取单个yaml
def get_yaml(fileDir):
fo=open(fileDir,‘r’,encoding=‘utf-8’)
res=yaml.load(fo,Loader=yaml.FullLoader)
return res
######33######读取多个yaml
def get_yaml(fileDir):
resList=[]
fo=open(fileDir,‘r’,encoding=‘utf-8’)
res=yaml.load_all(fo,Loader=yaml.FullLoader)
for item in res:
resList.append(item)
return resList