zoukankan      html  css  js  c++  java
  • ElementTree中的getchildren and getiterator

     36 # C:UsersjeguanDesktopTest_1.txt
     37 #
     38 # <?xml version="1.0"?>
     39 # <data>
     40 #       <country name="Liechtenstein">
     41 #           <rank>1</rank>
     42 #           <year>2008</year>
     43 #           <gdppc>141100</gdppc>
     44 #           <neighbor name="Austria" direction="E"/>
     45 #           <neighbor name="Switzerland" direction="W"/>
     46 #       </country>
     47 #       <country name="Singapore">
     48 #           <rank>4</rank>
     49 #           <year>2011</year>
     50 #           <gdppc>59900</gdppc>
     51 #           <neighbor name="Malaysia" direction="N"/>
     52 #       </country>
     53 #       <country name="Panama">
     54 #           <rank>68</rank>
     55 #           <year>2011</year>
     56 #           <gdppc>13600</gdppc>
     57 #           <neighbor name="Costa Rica" direction="W"/>
     58 #           <neighbor name="Colombia" direction="E"/>
     59 #       </country>
     60 # </data>
     61 #######################################################################
     62 def func2():
     63     from xml.etree import ElementTree
     64     xlsfile = r'C:UsersjeguanDesktopTest_1.txt'
     65
     66     root = ElementTree.parse(xlsfile).getroot()
     67    <span style="color:#FF0000;"><strong><span style="font-size:18px;"> ListNode = root.getiterator('rank')</span></strong></span>
     68     print(ListNode)
     69     # the output for print(ListNode) [<Element 'rank' at 0x6ffffc51450>, <Element 'rank' at 0x6ffffc51810>, <Element 'rank' at 0x6ffffc51950>]
     70     <span style="font-size:18px;color:#FF0000;"><strong>children = root.getchildren()</strong></span>
     71     print(children)
     72     # the output for print(children) is [<Element 'country' at 0x6ffffc50410>, <Element 'country' at 0x6ffffc507d0>, <Element 'country' at 0x6ffffc50910>]
    
    https://github.com/double12gzh/PythonLearning/blob/master/ElementTree.py
  • 相关阅读:
    Memcache第一篇---基础教程
    【分享】一位技术人员成长历程
    simhash
    Cookie mapping技术
    压缩编码基础知识
    shell vim--处理二进制文本
    CSDN泄漏数据完整分析
    day17 isinstance type issubclass 反射
    day16 类之间的关系 特殊成员
    day14 面向对象
  • 原文地址:https://www.cnblogs.com/double12gzh/p/10166231.html
Copyright © 2011-2022 走看看