boacontractor是用于*data*的模板库,即用于字典的模板。

boaconstructor的Python项目详细描述


boacontractor是data的模板库。

它允许您从其他模板构造python字典, 字典或实例。

github上提供了源代码:
此处提供文档:

示例

我将让代码和注释来完成对话:

from boaconstructor import Template

# Some shared information in a dict. This could also be a class instance
# or something else that supports getattr and hasattr.
#
common = dict(
    timeout = 30,
    email = "admin@example.com"
)

# This is a template created in a module. You need one of these. I pass in
# references that are available at this stage. The 'host.$.name' I will pass
# in at render time.
#
webserver_data = Template('webserver',
    dict(
        interface = 'host.$.name',
        port = 32189,
        timeout = 'common.$.timeout',
        alert_email = 'common.$.email',
    ),
    # This is uses common as an 'internal' reference
    references={'common':common}
)

# At run time I can pass 'external' references to resolve the hostnames.
# Maybe I got these from a database or some other source.
#
machine_1 = webserver_data.render({'host': {'name': 'myserver1'}}),
# {'alert_email': 'admin@example.com', 'interface': 'myserver1', 'port': 32189, 'timeout': 30}

machine_2 = webserver_data.render({'host': {'name': 'myserver2'}}),
# {'alert_email': 'admin@example.com', 'interface': 'myserver2', 'port': 32189, 'timeout': 30}


# Now I can pass these to Cheetah/Mako/etc to render a specific type of
# XML/INI/Text configuration files.

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

推荐PyPI第三方库


热门话题
java Intellij通过方法中的包查找用法   java中VS代码和打包命名的问题   将java CMS功能集成到具有高度动态内容的网站(Lucene/Mysql/Nosql)的策略   oracle的java类强制转换异常。jdbc。驾驶员OracleConnection   字节码向JVM添加上指令   如何在抽象类中执行java方法?   java是否可以在apache访问日志中排除指定的GET参数?(作者:W7开发环境)   java如何获取已安装音频播放器的列表?   尝试向HS学生展示如何使用Java访问MS数据库   使用正则表达式java对给定行中的特定字符串进行计数   java JOOQ Select查询中的Select计数   方法Java,如何从二维双精度数组中找到特定值?   获取图像URL的java正则表达式   java在切换到新的窗口驱动程序后找不到元素