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

python处理yml

发布时间:2020-12-20 10:31:11 所属栏目:Python 来源:网络整理
导读:import yaml # yaml文件转成字典 with open( ‘ a.yml ‘ , ‘ rb ‘ )as f: res = yaml.load(f,Loader= yaml.FullLoader) print (res)r = { ‘ tester ‘ : { ‘ appPackage ‘ : ‘ com.tencent.mobileqq ‘ , ‘ appActivity ‘ : ‘ com.tencent.mobileq
import yaml
#yaml文件转成字典
with open(a.yml,rb)as f:
    res = yaml.load(f,Loader=yaml.FullLoader)
print(res)

r = {tester: {appPackage: com.tencent.mobileqq,appActivity: com.tencent.mobileqq.activity.SplashActivity,noReset: True},device_type: android,devices: {android: [{ip: 127.0.0.1,port: 4723,udid: emulator-5554,platformVersion: 5.1.1,deviceName: emulator-5554,name: 雷电a,platformName: Android}]}}
#字符串写入yaml文件中
with open(a.yml,w,encoding=utf-8) as wf:
    res = yaml.dump(r,wf,allow_unicode = True)

(编辑:李大同)

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

    推荐文章
      热点阅读