python - 根据 YAML 1.1 规范, 'yes' 真的是 'true' 的别名吗? 1.2规范?

标签 python yaml pyyaml ruamel.yaml

我正在尝试调试一个问题,它归结为...

>>> 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

rumorsinternet 上关于"is"和“否”是保留字,它们也分别是 truefalse 的同义词。

但是只有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 Documentation ,

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/

相关文章:

python - 在 PyYAML 中创建自定义标签

python - 如何在 block 中的新行之后开始列出键

python - sys.exit(0) 和 os._exit(0) 有什么区别

amazon-web-services - CloudFormation YAML - 带有条件语句的 IAM 策略

python-3.x - 使用 Python3 为 Kubernetes 创建 YAML

amazon-web-services - AWS Code Deploy Error on Before Install 无法解决

linux - GitLab-Runner "listen_address not defined"错误

python - 我怎样才能知道 os.popen 是否在同一个 shell 中运行 linux 命令?

Python CV2 提取带字幕的视频帧

python - 检查 python 中浮点列的相等性