【发布时间】:2021-05-17 08:58:14
【问题描述】:
我有一个 .yaml 文件,里面有以下格式:
ament_tools:
release:
tags:
release: release/ardent/{package}/{version}
url: https://github.com/ros2-gbp/ament_tools-release.git
version: 0.4.0-0
source:
type: git
url: https://github.com/ament/ament_tools.git
version: ardent
status: maintained
cartographer:
release:
tags:
release: release/ardent/{package}/{version}
url: https://github.com/ros2-gbp/cartographer-release.git
version: 2.0.0-1
source:
type: git
url: https://github.com/ros2/cartographer.git
version: ardent
status: maintained
我想检索source 中的url 信息。到目前为止,上面的示例,我想检索https://github.com/ament/ament_tools.git 和https://github.com/ros2/cartographer.git URL。
我在下面写了一些代码,但本质上,我想将上面列出的 URL 添加到我已初始化的 urls 列表中。我该如何具体解析source,然后解析url?
def get_urls(distribution):
urls = list()
tag1 = "source"
tag2 = "url"
# Open distribution.yaml file and collect urls in list
for file in os.listdir("distribution/"):
if file.startswith(distribution):
dist_file = "distribution/" + file
stream = open(dist_file, 'r')
data = yaml.load(stream)
print(urls)
return urls
【问题讨论】:
标签: python parsing search yaml pyyaml