python xml文件的读写

2019-01-03  本文已影响0人  Cabcab
#! /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
上一篇下一篇

猜你喜欢

热点阅读