读取特殊字符时 ruamel 解析器错误
ruamel parser error on reading special characters
我正在使用 ruamel.yaml (0.15.37) 并且数据结构如下:
- !Message
Name: my message
Messages:
- !Message
name: InputMsg1
- !Variable
Name: control_word
Length: 8
Type: Signed
Unit: % # ruamel parser erro
如果我读取 YAML 文件,我会收到错误
File "_ruamel_yaml.pyx", line 904, in
_ruamel_yaml.CParser._parse_next_event (ext/_ruamel_yaml.c:12818) ruamel.yaml.scanner.ScannerError: while scanning for the next token
found character that cannot start any token
如果我以任何其他字符开头,则不会生成错误。
- !Message
Name: my message
Messages:
- !Message
name: InputMsg1
- !Variable
Name: control_word
Length: 8
Type: Signed
Unit: a % # no parser erro
我也试过了%
百分号是 indicator character 并且不能启动普通标量。所以你必须引用百分号:
Unit: "%"
或
Unit: '%'
(您也可以将其设为文字块标量:
Unit: |
%
或折叠标量,但我认为这不是更好的可读性)。
因为 &
也是一个指示字符,它会抛出同样的错误,但你似乎(错误地)假设你可以在 YAML 中进行 HTML 转义(你不能)。
我正在使用 ruamel.yaml (0.15.37) 并且数据结构如下:
- !Message
Name: my message
Messages:
- !Message
name: InputMsg1
- !Variable
Name: control_word
Length: 8
Type: Signed
Unit: % # ruamel parser erro
如果我读取 YAML 文件,我会收到错误
File "_ruamel_yaml.pyx", line 904, in _ruamel_yaml.CParser._parse_next_event (ext/_ruamel_yaml.c:12818) ruamel.yaml.scanner.ScannerError: while scanning for the next token found character that cannot start any token
如果我以任何其他字符开头,则不会生成错误。
- !Message
Name: my message
Messages:
- !Message
name: InputMsg1
- !Variable
Name: control_word
Length: 8
Type: Signed
Unit: a % # no parser erro
我也试过了%
百分号是 indicator character 并且不能启动普通标量。所以你必须引用百分号:
Unit: "%"
或
Unit: '%'
(您也可以将其设为文字块标量:
Unit: |
%
或折叠标量,但我认为这不是更好的可读性)。
因为 &
也是一个指示字符,它会抛出同样的错误,但你似乎(错误地)假设你可以在 YAML 中进行 HTML 转义(你不能)。