import yaml
import os
# 获取当前路径
filePath = os.path.dirname(__file__)
#print(filePath)
# 获取当前文件的绝对路径
fileNamePath = os.path.split(os.path.realpath(__file__))[0]
#print(fileNamePath)
# 获取配置文件的路径
yamlPath = os.path.join(fileNamePath,'config.yaml')
#print(yamlPath)
# 修改yaml配置
with open(yamlPath,'r') as f:
# print(f.read())
result = f.read()
x = yaml.load(result,Loader=yaml.FullLoader)
print(type(x))
print (x)
注释:请先安装pyyaml包再进行操作
安装命令: pip install pyyaml
以下为yaml 文件内容
name : Drivers
desc : Drivers desc sample
subs :
- name : 地图
desc : 地图
subs :
- name : 2D地图
desc : 2D地图
subs :
- name : map_load_2d
namecn : 加载 | 2D地图 暂未选择地图......
desc : 加载2D地图
probe:
run : roslaunch autolabor_navigation_launch r2ware_loadmap_2d.launch
runat: server
param: 加载2D地图
gui:
{}