ElementTree的点表示法
项目描述
概述
使用点表示法对ElementTree进行操作不是很好吗?此软件包允许
tree = ET.fromstring('<root><a><b c="asdf" /></a></root>')
a = tree.a
b = a.b
b.attrib['c'] == "asdf" # True
tree.a 将是一个 `Element <https://docs.pythonlang.cn/3.4/library/xml.etree.elementtree.html#xml.etree.ElementTree.Element>`__,具有额外的 `__getattr__ <https://github.com/arve0/objectifiedetree/blob/master/objectifiedetree/__init__.py#L11-12>`__ 方法。这意味着您可以使用元素,就像您通常所做的那样,但如果您的XML中的名称与Python的方法或属性冲突,则必须通过 tree.find(xpath) 来访问。
此软件包使用Python实现的etree,这使得它的速度比CPython中的etree慢。一个替代方案是将内置的通过 forbiddenfruit 进行猴子补丁,但我还没有考虑这一点。
objectifiedetree 已从 CPython 3.4 Lib/xml/etree 复制了etree的Python实现,并且可能仅适用于Python 3.4。
安装
使用 pip 进行安装…
pip install objectifiedetree
示例
from objectifiedetree import *
tree = ET.parse('/path/to/file.xml')
# dot notation :-)
el = tree.xpath.to.your.element
# use normal etree attributes
print(el.attrib)
# access name crashes
attrib_el = el.find('./attrib')
开发
安装依赖项并将objectifiedetree的开发版本链接到pip
git clone https://github.com/arve0/objectifiedetree
cd objectifiedetree
pip install -r requirements.txt # install dependencies and objectifiedetree-package
测试
tox
本地构建文档
要构建文档
pip install -r docs/requirements.txt
make docs
项目详情
关闭
objectifiedetree-0.0.1.tar.gz 的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | 4a79af55ca09e0239be4d6c0f85b58e6f96ccf9ca3361799d4f7b2932e1cb672 |
|
MD5 | d8f1c4dc91b63ceaa504b2c14ce09bf3 |
|
BLAKE2b-256 | 5a20d3223783b8e8c4a05bc07615de6e04ab203c6643d7e165c40800c6ae1d8d |
关闭
objectifiedetree-0.0.1-py2.py3-none-any.whl 的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | f8cfdff46c9e78dc7d6c806981733e32c57d29033b828a05021d580788bf37ce |
|
MD5 | 1c059389b5afedf8edfbb1f39cbe99a0 |
|
BLAKE2b-256 | 1b587abafae2a0bbe04ffcbccb13d406f25569788cb32ee4d98d526ece6f9ad0 |