python 修改yaml文件数据

#!/usr/bin/env python

-- coding: utf-8 --

import yaml
from string import Template

def set_yaml(set_x,set_y,set_yaw):

def set_yaml():

# with open ("20220222.yaml",encoding = "utf-8") as f:
#     re = Template(f.read()).substitute(data)
#     print(re,type(re))
#     print (yaml.safe_load(stream=re),type(yaml.safe_load(stream=re)))



with open('/home/neousys/wqw/pick_place/src/pick_demo/src/20220222.yaml') as f:
    doc = yaml.safe_load(f)

# for ele in doc['stations'][0]['info']:
#     if ele['name'] == "1":
#         print("11111")

if doc['stations'][0]['info']['name']== 1:
#    doc['stations'][0]['pose']['x'] = set_x
#    doc['stations'][0]['pose']['y'] = set_y
#    doc['stations'][0]['pose']['yaw'] = set_yaw
    doc['stations'][0]['pose']['x'] = 17.5
    doc['stations'][0]['pose']['y'] = 18
    doc['stations'][0]['pose']['yaw'] = 16.8
    print(doc['stations'][0]['pose']['x'])


with open('/home/neousys/wqw/pick_place/src/pick_demo/src/20220222.yaml','w') as f:
    yaml.dump(doc,f)

if name == ‘main’:
set_yaml()

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值