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

    <tfoot id='VXIxR'></tfoot>

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

      1. YAML:转储不带引号的 Python 列表

        时间:2023-09-13

      2. <legend id='CIVWJ'><style id='CIVWJ'><dir id='CIVWJ'><q id='CIVWJ'></q></dir></style></legend>

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

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

                • <bdo id='CIVWJ'></bdo><ul id='CIVWJ'></ul>
                  本文介绍了YAML:转储不带引号的 Python 列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我有一个 Python 列表 my_list,它看起来像这样 ["test1", "test2", "test3"].我只是想将它转储到不带引号的 YAML 文件中.所以想要的输出是:

                  I have a Python list, my_list that looks like this ["test1", "test2", "test3"]. I simply want to dump it to a YAML file without quotes. So the desired output is:

                  test_1
                  test_2
                  test_3
                  

                  我试过了:

                  import yaml
                  with open("my_yaml.yaml", "w") as f:
                      yaml.safe_dump(my_list, f)
                  

                  不幸的是,这包括一行中的所有 3 个元素,并且它们被引用了:

                  Unfortunately, this includes all 3 elements on a single line and they're quoted:

                  'test_1'、'test_2'、'test_3'

                  如何修改以获得所需的输出?

                  How can I modify to get the desired output?

                  推荐答案

                  尝试使用 default_style=None 避免使用引号,并使用 default_flow_style=False 将项目输出到不同的行:

                  Try using default_style=None to avoid quotes, and default_flow_style=False to output items on separate lines:

                  yaml.safe_dump(my_list, f, default_style=None, default_flow_style=False)
                  

                  这篇关于YAML:转储不带引号的 Python 列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:'yaml.parser.ParserError: expected '&lt;document 下一篇:如何为 ruamel.yaml 创建自定义 yaml 映射转储程序

                  相关文章

                  最新文章

                  <tfoot id='8ZlRu'></tfoot>

                • <small id='8ZlRu'></small><noframes id='8ZlRu'>

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