<small id='1qgOp'></small><noframes id='1qgOp'>

      <tfoot id='1qgOp'></tfoot>
      <legend id='1qgOp'><style id='1qgOp'><dir id='1qgOp'><q id='1qgOp'></q></dir></style></legend>
          <bdo id='1qgOp'></bdo><ul id='1qgOp'></ul>

        <i id='1qgOp'><tr id='1qgOp'><dt id='1qgOp'><q id='1qgOp'><span id='1qgOp'><b id='1qgOp'><form id='1qgOp'><ins id='1qgOp'></ins><ul id='1qgOp'></ul><sub id='1qgOp'></sub></form><legend id='1qgOp'></legend><bdo id='1qgOp'><pre id='1qgOp'><center id='1qgOp'></center></pre></bdo></b><th id='1qgOp'></th></span></q></dt></tr></i><div id='1qgOp'><tfoot id='1qgOp'></tfoot><dl id='1qgOp'><fieldset id='1qgOp'></fieldset></dl></div>

        “!"上的 pyYAML 错误在一个字符串中

        时间:2023-09-12
      1. <small id='UX8of'></small><noframes id='UX8of'>

        <i id='UX8of'><tr id='UX8of'><dt id='UX8of'><q id='UX8of'><span id='UX8of'><b id='UX8of'><form id='UX8of'><ins id='UX8of'></ins><ul id='UX8of'></ul><sub id='UX8of'></sub></form><legend id='UX8of'></legend><bdo id='UX8of'><pre id='UX8of'><center id='UX8of'></center></pre></bdo></b><th id='UX8of'></th></span></q></dt></tr></i><div id='UX8of'><tfoot id='UX8of'></tfoot><dl id='UX8of'><fieldset id='UX8of'></fieldset></dl></div>
            <tbody id='UX8of'></tbody>

              1. <tfoot id='UX8of'></tfoot>

                <legend id='UX8of'><style id='UX8of'><dir id='UX8of'><q id='UX8of'></q></dir></style></legend>

                  <bdo id='UX8of'></bdo><ul id='UX8of'></ul>
                  本文介绍了“!"上的 pyYAML 错误在一个字符串中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  首先,免责声明:我对 YAML 不太熟悉.我正在尝试将 YAML 文档解析为键值对(不用担心我是怎么做的.我已经处理好了)

                  First, a disclaimer: I'm not too familiar with YAML. I'm trying to parse a YAML doc into Key Value Pairs (don't worry about how I'm doing it. I've got that bit handled)

                  我的文件曾经看起来像:

                  My file used to look something like:

                  world:
                       people:
                            name:Suzy
                            address:chez-bob
                  

                  然后,有人去改了.

                  world:
                       people:
                            name:!$uzy
                            address:chez-bob
                  

                  我得到这个解析错误:

                  yaml.constructor.ConstructorError: could not determine a constructor for the tag '!$uzy'
                  

                  这甚至意味着什么?我将如何让它仅将 !$ 解释为两个字符?我只想要一个字符串键和值的字典!此外,编辑 yaml 文件不是一种选择.必须使用解析器在代码中修复问题.

                  What does this even mean? How would I go about getting it to just interpret !$ as just two characters? I just want a dictionary of string keys and values! Also, editing the yaml files is not an option. Problem must be fixed in the code using the parser.

                  推荐答案

                  感叹号是YAML标签的前缀.解析器必须通过标签名称为它实现一个构造函数.有一些默认标签,如 !!bool!!int 等,甚至还有一些 Python 特定标签,如 !!python/tuple.

                  Exclamation mark is a prefix for YAML tags. The parser has to implement a constructor for it by the tag name. There are some default tags like !!bool, !!int, etc. and even some Python specific tags like !!python/tuple.

                  您可以定义自己的构造函数,甚至可以为前缀捕获的多个标签定义构造函数.通过定义 '' 的前缀,您可以捕获所有标签并忽略它们.您可以从构造函数返回标签及其值,将其全部视为文本.

                  You can define your own constructors and even constructors for multiple tags caught by a prefix. By defining the prefix to '', you can catch all the tags and ignore them. You can return the tag and its value from the constructor to just treat it all as text.

                  >>> import yaml
                  >>> def default_ctor(loader, tag_suffix, node):
                  ...     print loader
                  ...     print tag_suffix
                  ...     print node
                  ...     return tag_suffix + ' ' + node.value
                  ...
                  >>> yaml.add_multi_constructor('', default_ctor)
                  >>> yaml.load(y)
                  <yaml.loader.Loader object at 0xb76ce8ec>
                  !$uzy
                  ScalarNode(tag=u'!$uzy', value=u'')
                  {'world': {'people': {'name': '!$uzy', 'address': 'chez-bob'}}}
                  >>>
                  

                  这篇关于“!"上的 pyYAML 错误在一个字符串中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:在 python 中读取 YAML 配置文件并使用变量 下一篇:使用 Python 在 YAML 中获取重复键

                  相关文章

                  最新文章

                  • <bdo id='DMcI3'></bdo><ul id='DMcI3'></ul>
                • <i id='DMcI3'><tr id='DMcI3'><dt id='DMcI3'><q id='DMcI3'><span id='DMcI3'><b id='DMcI3'><form id='DMcI3'><ins id='DMcI3'></ins><ul id='DMcI3'></ul><sub id='DMcI3'></sub></form><legend id='DMcI3'></legend><bdo id='DMcI3'><pre id='DMcI3'><center id='DMcI3'></center></pre></bdo></b><th id='DMcI3'></th></span></q></dt></tr></i><div id='DMcI3'><tfoot id='DMcI3'></tfoot><dl id='DMcI3'><fieldset id='DMcI3'></fieldset></dl></div>

                    <small id='DMcI3'></small><noframes id='DMcI3'>

                    <tfoot id='DMcI3'></tfoot>

                    1. <legend id='DMcI3'><style id='DMcI3'><dir id='DMcI3'><q id='DMcI3'></q></dir></style></legend>