【发布时间】:2019-03-14 11:10:54
【问题描述】:
我正在编写一个单元测试,我发现了一个使用制表符缩进编写 YAML 配置的工具,但是当我尝试使用 yaml.load(file_object) 读取它时,我收到一条错误消息:
(<unknown>): found character that cannot start any token while scanning for the next token at line 2 column 1
或使用我在终端中看到的工具:
while scanning for the next token
found character '\t' that cannot start any token
in "/user/config/settings", line 2, column 1
【问题讨论】:
-
YAML 中不允许制表符缩进(参见规范中的6.1 Indentation Spaces:“为了保持可移植性,制表符不能用于缩进,因为不同的系统对制表符的处理方式不同”)。你的问题到底是什么?
-
好吧,我通读了 yaml 的文档,并没有说它允许选项卡,但是我遇到了一个 PyQT UI 工具,它正在编写 yaml 文件选项卡,我的代码试图检查用户配置得到错误以上。您已经回答了我的问题,但是在某些旧的 yaml 版本中是否支持过选项卡?
-
这很令人惊讶,我会说这是工具中的错误,可以报告。似乎标签缩进已被禁止since the oldest historical version of the specification。标准 YAML 库正确地做到了这一点,所以我认为这是一个糟糕的自定义 YAML 生成。我认为许多情况(不确定是否全部)可以通过用固定数量的空格替换初始选项卡来“修复”。