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

      <legend id='arPXv'><style id='arPXv'><dir id='arPXv'><q id='arPXv'></q></dir></style></legend>
    2. <small id='arPXv'></small><noframes id='arPXv'>

          <bdo id='arPXv'></bdo><ul id='arPXv'></ul>
      1. 如何防止 YAML 在没有新行的情况下转储长行

        时间:2023-09-13
      2. <tfoot id='bgbGd'></tfoot>
          <tbody id='bgbGd'></tbody>
        • <bdo id='bgbGd'></bdo><ul id='bgbGd'></ul>

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

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

                1. <i id='bgbGd'><tr id='bgbGd'><dt id='bgbGd'><q id='bgbGd'><span id='bgbGd'><b id='bgbGd'><form id='bgbGd'><ins id='bgbGd'></ins><ul id='bgbGd'></ul><sub id='bgbGd'></sub></form><legend id='bgbGd'></legend><bdo id='bgbGd'><pre id='bgbGd'><center id='bgbGd'></center></pre></bdo></b><th id='bgbGd'></th></span></q></dt></tr></i><div id='bgbGd'><tfoot id='bgbGd'></tfoot><dl id='bgbGd'><fieldset id='bgbGd'></fieldset></dl></div>
                  本文介绍了如何防止 YAML 在没有新行的情况下转储长行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  在转储/序列化输入中具有长行的数据时,pyyaml 会在新行中添加额外的缩进 - 这很烦人,我们如何避免在两行/多行中进行这种转换?

                  While dumping/serializing data having long lines in input, pyyaml adds extra indentation with new line - which is annoying, how can we avoid this conversion in two lines / multiple lines ?

                  例如

                  在 [1] 中:

                  x = "-c /home/user/test/test2/test23/tet/2s/test1/stest/longdirectory1/directory2/ --optnion12 --verbose"
                  

                  在[2]中:导入yaml

                  在 [3] 中:print (yaml.dump([dict(ATTRIBUTES=[dict(CONFIG=x)])], default_flow_style=False))

                  一个错误

                  - ATTRIBUTES:
                    - CONFIG: -c /home/user/test/test2/test23/tet/2s/test1/stest/longdirectory1/directory2/
                        --optnion12 --verbose
                  

                  应该是这样的

                  - ATTRIBUTES:
                    - CONFIG: -c /home/user/test/test2/test23/tet/2s/test1/stest/longdirectory1/directory2/ --optnion12 --verbose
                  

                  推荐答案

                  感谢@MathieuMarques 建议查看@dump 选项和提供的链接,YAML 文档不够好,无法找到.

                  Thanks @MathieuMarques for suggesting to look @ dump options and link provided, YAML documentation was not good enough to find it out.

                  无论如何,解决方案是为 dump 函数指定 width 参数.

                  Anyways solution is to specify width parameter for dump function.

                  yaml.dump(data, width=1000)

                  @RandomCoder 建议使用 yaml.dump(data, width=float("inf")) 永久解决方案.

                  A better approach suggested by @RandomCoder to use yaml.dump(data, width=float("inf")) for a permanent solution.

                  这篇关于如何防止 YAML 在没有新行的情况下转储长行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:jinja2 嵌套变量 下一篇:换行符和破折号在 jinja 中无法正常工作

                  相关文章

                  最新文章

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

                    • <bdo id='Htthj'></bdo><ul id='Htthj'></ul>
                      <legend id='Htthj'><style id='Htthj'><dir id='Htthj'><q id='Htthj'></q></dir></style></legend>

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

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