python读取和解析xml文件

import xml.etree.ElementTree as ET


def parse_rec(filename):
    """Parse a PASCAL VOC xml file."""
    tree = ET.parse(filename)
    objects = []
    for obj in tree.findall('object'):
        obj_struct = {}
        obj_struct['name'] = obj.find('name').text
        rbox = obj.find('rbox')
        obj_struct['rbox'] = [float(rbox.find('cx').text),
                              float(rbox.find('cx').text),
                              float(rbox.find('w').text),
                              float(rbox.find('h').text),
                              float(rbox.find('angle').text)]
        objects.append(obj_struct)
    return objects

你可能感兴趣的:(Python,python,人工智能)