加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Python > 正文

使用python读取yaml文件

发布时间:2020-12-17 17:06:44 所属栏目:Python 来源:网络整理
导读:在做APP测试时,通常需要把参数存到一个字典变量中,这时可以将参数写入yaml文件中,再读取出来。 新建yaml文件(android_caps.yaml),文件内容为: ? 1 platformName: Android 2 platformVersion: ' 5.1 ' 3 deviceName: Android Emulator 4 appPackage: com

在做APP测试时,通常需要把参数存到一个字典变量中,这时可以将参数写入yaml文件中,再读取出来。

新建yaml文件(android_caps.yaml),文件内容为:

?

1 platformName: Android
2 platformVersion: '5.1'
3 deviceName: Android Emulator
4 appPackage: com.xx.xx
5 appActivity: com.xx.xx.activity.WelcomeActivity

?

python读取yaml文件:

?

1 import yaml
2 text = yaml.load(open('android_caps.yaml'),Loader=yaml.FullLoader) 
3 print(text)
4 print(type(text))

?

输出结果为:

{'deviceName': 'Android Emulator','platformName': 'Android','platformVersion': '5.1','appActivity': 'com.xx.xx.activity.WelcomeActivity','appPackage': 'com.xx.xx'}
<class 'dict'>

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读