用于在python中创建结构化文档的dsl。

datatree的Python项目详细描述


摘要

datatree是用python创建结构化文档的dsl。灵感来自 ruby builder但目的是减少相关的线噪声 在python中创建xml文档。作为额外的奖励,可以输出树 到任何结构化格式(库中支持xml、json和yaml)。

注意:很快就会有更多的文档,但是现在一个非常基本的草稿可以是 在datatree.readthedocs.org找到。

安装

您可以通过PyPi或直接安装 来自github回购协议。

使用pip安装:

$ pip install datatree

使用简易安装进行安装:

$ easy_install datatree

示例

一个小例子:

from datatree import Tree, Node

tree = Tree()
with tree.author() as author:
    author.name('Terry Pratchett')
    author.genre('Fantasy/Comedy')
    author // "Only 2 books listed"
    with author.novels(count=2) as novels:
        novels.novel('Small Gods', year=1992)
        novels.novel('The Fifth Elephant', year=1999)
        novels << Node("novel", "Guards! Guards!", year=1989)

print tree(pretty=True)

生成xml:

<author>
    <name>Terry Pratchett</name>
    <genre>Fantasy/Comedy</genre>
    <!-- Only 2 books listed -->
    <novels count="2">
        <novel year="1992">Small Gods</novel>
        <novel year="1999">The Fifth Elephant</novel>
        <novel year="1989">Guards! Guards!</novel>
    </novels>
</author>

或者json:

{
    "author": {
        "genre": "Fantasy/Comedy",
        "name": "Terry Pratchett",
        "novels": [
            "Small Gods",
            "The Fifth Elephant",
            "Guards! Guards!"
        ]
    }
}

或者山药:

author:
  genre: Fantasy/Comedy
  name: Terry Pratchett
  novels: [Small Gods, The Fifth Elephant, Guards! Guards!]

许可证

这项工作是根据Apache License, Version 2.0授权的。

源代码

源代码可以在github上找到。

反馈

我欢迎任何和所有建设性的反馈。随时联系我(杰森·韦伯) www.bigjason.com或在twitter上 @bigjasonwebb

贡献

欢迎捐款。只要在github上叉子,我会尽量做出反应 尽可能的。

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
带Maven的Eclipse Java存储库:缺少工件:compile   java如何以编程方式停止RMI服务器并通知所有客户端   java Roboguice抛出ClassNotFoundException:AnnotationDatabaseImpl   java为什么lucene 4.0删除IndexWriter类的两个构造函数?   nls如何避免java项目上不需要的日志消息?   测试无法在Selenium Webdriver(java)中定位iframe   使用XML的java servlet   java如何使用jxl用****屏蔽单元格   java使用SQLite从数据库中选择“没有这样的列”   导入扫描程序后出现java编译错误   插入查询的java空指针异常   使用创建PostgreSQL数据库。Java应用中的sql脚本   java使用jsoup将HTML解析为格式化的明文