我正在尝试调试一个问题,它归结为...
>>> import yaml as pyyaml
>>> import ruamel.yaml as ruamel
>>> ruamel.load("x: yes") == ruamel.load("x: true")
False
>>> pyyaml.safe_load("x: yes") == pyyaml.safe_load("x: true")
True
有rumors在 internet 上关于"is"和“否”是保留字,它们也分别是 true
和 false
的同义词。
但是只有passing mention在 1.1 规范中但没有详细说明,并且字符串“yes”没有出现在 1.2 spec 中完全没有。
其实翻看every draft of the spec它仅以任何合法方式以合法方式出现在 https://yaml.org/spec/history/2002-09-01.html 中并在之后的修订中被删除。
我怀疑我在编写它的过程中已经回答了我自己的问题,但是......这个关于“是/否”的业务只是胡说八道而进入了实现(我的编辑甚至突出显示“是/否” "作为特殊),还是我误解或遗漏了规范的一部分?
最佳答案
在 yaml 规范 1.1 中将 yes
/no
解释为 true
/false
是有意设计的documented .然而,在 yaml 规范 1.2 中,将 yes
/no
解释为 true
/false
已被删除。
PyYAML supports the YAML 1.1 standard,
ruamel.yaml
supports YAML 1.2 as released in 2009.YAML 1.2 dropped support for several features unquoted
Yes
,No
,On
,Off
关于python - 根据 YAML 1.1 规范, 'yes' 真的是 'true' 的别名吗? 1.2规范?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57682657/