【发布时间】:2021-08-02 09:44:51
【问题描述】:
我有一个如下所示的 yaml 文件:
Histograms:
zee:
bins: {"fix": [55, 0.1 ,35e3]}
Title: "é isso ai"
Xlabel: "como assim"
Ylabel: "Z #rightarrow e^{+}e^{-}"
ymax: 35e3
ymim: 0.1
color: 4 #root.kAzure+3
scale: 1.0
ztautau:
ymax: 35e3
ymim: 0.1
ymaxp: 1.19
ymimp: 0.81
label: "Z #rightarrow e^{+}e^{-}"
color: ""
ttbar:
ymax: 35e3
ymim: 0.1
ymaxp: 1.19
ymimp: 0.81
label: "Z #rightarrow e^{+}e^{-}"
wplustaunu:
bins: {"fix": [55, 0.1 ,35e3]}
Title: "é isso ai"
Xlabel: "como assim"
Ylabel: "Z #rightarrow e^{+}e^{-}"
ymax: 35e3
ymim: 0.1
color: "root.kAzure+3"
scale: 1.0
我需要通过循环获取以下字符串:zee,ztautau,ttbar,wplustaunu(我猜它们是字典的标题?)。我的意思是我需要通过一个循环(在 python 中)来处理它们,因为我需要处理有很多这样的字典的文件,所以我自己知道它们不是一个好的选择。但是我一直在研究这个问题并且无法找到解决方案,所以如果有人可以帮助我或给我一些参考,我将非常感激。
我想要的输出是:
泽
兹陶陶
ttbar
wplusenu
我不想要更多,只是这些数据。有可能吗?
感谢关注!
【问题讨论】:
-
向我们展示您期望的输出。获取字符串很容易,但我想还有更多。是否要将子条目作为嵌套字典?
-
而且,顺便说一下,还有一个用于 Python 的 YAML 解析器:pyyaml.org/wiki/PyYAMLDocumentation
标签: python list dictionary yaml