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

    <bdo id='C6Miy'></bdo><ul id='C6Miy'></ul>

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

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

<tfoot id='C6Miy'></tfoot>
      1. 将 YAML 文件转换为 Python JSON 对象

        时间:2023-09-12
          <bdo id='rwxYz'></bdo><ul id='rwxYz'></ul>
        • <small id='rwxYz'></small><noframes id='rwxYz'>

              <tfoot id='rwxYz'></tfoot>
                <tbody id='rwxYz'></tbody>

                  <i id='rwxYz'><tr id='rwxYz'><dt id='rwxYz'><q id='rwxYz'><span id='rwxYz'><b id='rwxYz'><form id='rwxYz'><ins id='rwxYz'></ins><ul id='rwxYz'></ul><sub id='rwxYz'></sub></form><legend id='rwxYz'></legend><bdo id='rwxYz'><pre id='rwxYz'><center id='rwxYz'></center></pre></bdo></b><th id='rwxYz'></th></span></q></dt></tr></i><div id='rwxYz'><tfoot id='rwxYz'></tfoot><dl id='rwxYz'><fieldset id='rwxYz'></fieldset></dl></div>
                  <legend id='rwxYz'><style id='rwxYz'><dir id='rwxYz'><q id='rwxYz'></q></dir></style></legend>
                1. 本文介绍了将 YAML 文件转换为 Python JSON 对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  如何加载 YAML 文件并将其转换为 Python JSON 对象?

                  How can I load a YAML file and convert it to a Python JSON object?

                  我的 YAML 文件如下所示:

                  My YAML file looks like this:

                  Section:
                      heading: Heading 1
                      font: 
                          name: Times New Roman
                          size: 22
                          color_theme: ACCENT_2
                  
                  SubSection:
                      heading: Heading 3
                      font:
                          name: Times New Roman
                          size: 15
                          color_theme: ACCENT_2
                  Paragraph:
                      font:
                          name: Times New Roman
                          size: 11
                          color_theme: ACCENT_2
                  Table:
                      style: MediumGrid3-Accent2
                  

                  推荐答案

                  你可以使用PyYAMLp>

                  you can use PyYAML

                  pip install PyYAML
                  

                  在 ipython 控制台中:

                  And in the ipython console:

                  In [1]: import yaml
                  
                  In [2]: document = """Section:
                     ...:     heading: Heading 1
                     ...:     font: 
                     ...:         name: Times New Roman
                     ...:         size: 22
                     ...:         color_theme: ACCENT_2
                     ...: 
                     ...: SubSection:
                     ...:     heading: Heading 3
                     ...:     font:
                     ...:         name: Times New Roman
                     ...:         size: 15
                     ...:         color_theme: ACCENT_2
                     ...: Paragraph:
                     ...:     font:
                     ...:         name: Times New Roman
                     ...:         size: 11
                     ...:         color_theme: ACCENT_2
                     ...: Table:
                     ...:     style: MediumGrid3-Accent2"""
                     ...:     
                  
                  In [3]: yaml.load(document)
                  Out[3]: 
                  {'Paragraph': {'font': {'color_theme': 'ACCENT_2',
                     'name': 'Times New Roman',
                     'size': 11}},
                   'Section': {'font': {'color_theme': 'ACCENT_2',
                     'name': 'Times New Roman',
                     'size': 22},
                    'heading': 'Heading 1'},
                   'SubSection': {'font': {'color_theme': 'ACCENT_2',
                     'name': 'Times New Roman',
                     'size': 15},
                    'heading': 'Heading 3'},
                   'Table': {'style': 'MediumGrid3-Accent2'}}
                  

                  这篇关于将 YAML 文件转换为 Python JSON 对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:解析 YAML,返回行号 下一篇:使用 Python 读取 YAML 文件会导致 yaml.composer.Compo

                  相关文章

                  最新文章

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

                2. <tfoot id='rLbEV'></tfoot>
                  • <bdo id='rLbEV'></bdo><ul id='rLbEV'></ul>
                  1. <small id='rLbEV'></small><noframes id='rLbEV'>