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

  • <small id='yjmm5'></small><noframes id='yjmm5'>

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

        如何用python解析YAML字符串?

        How do I parse a yaml string with python?(如何用python解析YAML字符串?)

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

              <legend id='pDZ6L'><style id='pDZ6L'><dir id='pDZ6L'><q id='pDZ6L'></q></dir></style></legend>
                <tbody id='pDZ6L'></tbody>

            1. <tfoot id='pDZ6L'></tfoot>
              <i id='pDZ6L'><tr id='pDZ6L'><dt id='pDZ6L'><q id='pDZ6L'><span id='pDZ6L'><b id='pDZ6L'><form id='pDZ6L'><ins id='pDZ6L'></ins><ul id='pDZ6L'></ul><sub id='pDZ6L'></sub></form><legend id='pDZ6L'></legend><bdo id='pDZ6L'><pre id='pDZ6L'><center id='pDZ6L'></center></pre></bdo></b><th id='pDZ6L'></th></span></q></dt></tr></i><div id='pDZ6L'><tfoot id='pDZ6L'></tfoot><dl id='pDZ6L'><fieldset id='pDZ6L'></fieldset></dl></div>
                  <bdo id='pDZ6L'></bdo><ul id='pDZ6L'></ul>
                  本文介绍了如何用python解析YAML字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我看到一个API和许多如何解析YAML文件的示例,但是字符串呢?

                  推荐答案

                  这是迄今为止我见过的最好的示例演示方式:

                  import yaml
                  
                  dct = yaml.safe_load('''
                  name: John
                  age: 30
                  automobiles:
                  - brand: Honda
                    type: Odyssey
                    year: 2018
                  - brand: Toyota
                    type: Sienna
                    year: 2015
                  ''')
                  assert dct['name'] == 'John'
                  assert dct['age'] == 30
                  assert len(dct["automobiles"]) == 2
                  assert dct["automobiles"][0]["brand"] == "Honda"
                  assert dct["automobiles"][1]["year"] == 2015
                  

                  这篇关于如何用python解析YAML字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  groupby multiple coords along a single dimension in xarray(在xarray中按单个维度的多个坐标分组)
                  Group by and Sum in Pandas without losing columns(Pandas中的GROUP BY AND SUM不丢失列)
                  Group by + New Column + Grab value former row based on conditionals(GROUP BY+新列+基于条件的前一行抓取值)
                  Groupby and interpolate in Pandas(PANDA中的Groupby算法和插值算法)
                  Pandas - Group Rows based on a column and replace NaN with non-null values(PANAS-基于列对行进行分组,并将NaN替换为非空值)
                  Grouping pandas DataFrame by 10 minute intervals(按10分钟间隔对 pandas 数据帧进行分组)
                  <tfoot id='BocKW'></tfoot>
                  <legend id='BocKW'><style id='BocKW'><dir id='BocKW'><q id='BocKW'></q></dir></style></legend>

                    • <bdo id='BocKW'></bdo><ul id='BocKW'></ul>
                        <tbody id='BocKW'></tbody>

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

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