util.py 文件源码

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

项目:calcit 作者: cstein 项目源码 文件源码
def substitute_file(from_file, to_file, substitutions):
    """ Substitute contents in from_file with substitutions and
        output to to_file using string.Template class

        Raises: IOError file the file to replace from is not found

        Arguments:
        ----------
        from_file -- template file to load
        to_file -- substituted file
        substitutions -- dictionary of substitutions.
    """
    with open(from_file, "r") as f_in:
        source = string.Template(f_in.read())

        with open(to_file, "w") as f_out:
            outcome = source.safe_substitute(substitutions)
            f_out.write(outcome)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号