templates.py 文件源码

python
阅读 22 收藏 0 点赞 0 评论 0

项目:s2e-env 作者: S2E 项目源码 文件源码
def render_template(context, template, path=None, executable=False):
    """
    Renders the ``template`` template with the given ``context``. The result is
    written to ``path``. If ``path`` is not specified, the result is
    returned as a string
    """
    env = _init_template_env()
    data = env.get_template(template).render(context)

    if not path:
        return data

    with open(path, 'w') as f:
        f.write(data)

    if executable:
        st = os.stat(path)
        os.chmod(path, st.st_mode | stat.S_IEXEC)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号