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)
评论列表
文章目录