ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

UI自动化之yaml格式介绍

2022-02-09 11:03:44  阅读:125  来源: 互联网

标签:cus003 python data 如下 yaml UI 格式 type


yaml格式介绍

对象

这应该算是最简单的一种格式了,就是一组键值对

1. 新建data.yaml文件,内容如下:

 

 脚本如下:

 

 转换为python后:

{'code': 'cus001', 'type': 'market', 'name': 'waiqin365'}

修改yaml文件,格式如下:

 

 转换为python后:

{'name': 'waiqin365', 'detail': {'code': 'cus001', 'type': 'market'}}

数组

一组连词线开头的行,构成一个数组

1.新建data.yaml,格式如下:

 

 转换为python后:

['cus001', 'cus002', 'cus003']

修改yaml文件,格式如下:

 

 转换为python后:

[{'cus001': {'code': 'code001'}}, {'cus002': {'code': 'code002', 'type': 'tyoe002'}}, 'cus003']

 

多个对象

1.新建data.yaml,格式如下:

备注:这是官方wiki文档的例子

 

 需要修改python脚本,改用load_all来解析文档:

 

 转换为python后:

{'name': "The Set of Gauntlets 'Pauraegen'", 'description': 'A set of handgear with sparks that crackle across its knuckleguards.'}
{'name': "The Set of Gauntlets 'Paurnen'", 'description': 'A set of gauntlets that gives off a foul,acrid odour yet remains untarnished.'}
{'name': "The Set of Gauntlets 'Paurnimmen'", 'description': 'A set of handgear, freezing with unnatural cold.'}

对象和数组结合

1.新建data.yaml,格式如下:

 

 转换为python后:

{'cus': ['cus001', 'cus002', 'cus003'], 'detail': {'dept': 'dept1', 'type': {'type1': 'a'}}}

读取中文显示问题

当data.yaml文件中,含有中文时,读取后显示有问题:
如下,data.yaml文件为:

 

 用上面脚本,直接打印出来结果为:

{'cus': [u'\u7ec8\u7aef001', u'\u7ec8\u7aef002', 'cus003'], 'detail': {'dept': 'dept1', 'type': {'type1': 'a'}}}

如何才能直接将 cus:['终端001','终端002','终端003'] 打印出来呢?

修改脚本如下:

 

 

对比一下,打印结果如下:
{'cus': [u'\u7ec8\u7aef001', u'\u7ec8\u7aef002', 'cus003'], 'detail': {'dept': 'dept1', 'type': {'type1': 'a'}}}
{'cus': [u'终端001', u'终端002', 'cus003'], 'detail': {'dept': 'dept1', 'type': {'type1': 'a'}}}     转自
作者:迈阿密小白
链接:https://www.jianshu.com/p/bba511a12896




 

 

 

标签:cus003,python,data,如下,yaml,UI,格式,type
来源: https://www.cnblogs.com/aleac/p/15874144.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有