一组方便的模块,几乎可以保证会给你带来麻烦。
dhp的Python项目详细描述
dhp是一个几乎可以保证会给您带来麻烦的代码片段库。
我从一个小贩那里拿到的,在Pycon外面的拐角处。
事实上,这是一个不断增长的程序库,我发现它不时有帮助。我想你也可以。
短语手册内容示例
有关完整的列表,请参见Full Documentation。
dhp.doq
- DOQ Data Object Query mapper. Query simple data sources with an ORM like style.
from dhp.doq import DOQ doq = DOQ(data_objects=data_source) for rec in doq.filter(occupation='Publisher'): print(rec)
dhp.结构
- DictDot - subclasses Python’s built-in dict object and offers attribute access to the dictionary.
from dhp.structures import DictDot my_dict = {'hovercraft': 'eels', 'speed': 42} dicdot = DictDot(my_dict) assert dicdot.hovercraft == 'eels' assert dicdot.speed == 42
dhp.测试
- tempfile_containing - generate a temporary file that contains indicated contents and returns the filename for use. When finished the tempfile is removed.
from dhp.test import tempfile_containing contents = 'I will not buy this record, it is scratched.' with tempfile_containing(contents) as fname: do_something(fname)
dhp.xml
- xml_to_dict - parse any ugly xml to a python dictionary.
from dhp.xml import xml_to_dict xml = '<vehicle type="Hovercraft"><filled/><cargo>eels</cargo></vehicle>' xml_to_dict(xml) {'vehicle': {'@type':'Hovercraft', 'cargo':'eels', 'filled': None} }
要求
没有。
安装
确保得到最新版本。
pip install dhp