ElementTree中的getchildren and getiterator
生活随笔
收集整理的這篇文章主要介紹了
ElementTree中的getchildren and getiterator
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
36 # C:\Users\jeguan\Desktop\Test_1.txt37 #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 ElementTree64 xlsfile = r'C:\Users\jeguan\Desktop\Test_1.txt'6566 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
轉載于:https://www.cnblogs.com/double12gzh/p/10166231.html
總結
以上是生活随笔為你收集整理的ElementTree中的getchildren and getiterator的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: JQ基础语法
- 下一篇: windows系统路径环境变量