美文网首页
python xml文件的读写

python xml文件的读写

作者: Cabcab | 来源:发表于2019-01-03 20:32 被阅读0次
    #! /usr/bin/env python
    
    import sys
    import os
    try:
        import xml.etree.cElementTree as ET 
    except ImportError:
        import xml.etree.ElementTree as ET
    # -*- coding:utf-8 -*-
    
    
    #list
    tree = ET.parse("test.xml")
    root = tree.getroot()
    
    for i in root:
        print i.text  #i is child of root . print the content of i
        i.set('lalala',"blahblah")  #add an attribution to i
        print i.attrib #print all attribution
    

    相关文章

      网友评论

          本文标题:python xml文件的读写

          本文链接:https://www.haomeiwen.com/subject/aoiqrqtx.html