[Read template file] Read a text file and return it as a Template object #python
# Template objects allows you to add ${FIELD_NAME} tags into the file
# and then values can be substituted with
# template_object.substitute(FIELD_NAME = <field_value>)
def read_template(filename):
"""
Returns a Template object comprising the contents of the
file specified by filename.
"""
import Template
with open(filename, 'r', encoding='utf-8') as template_file:
template_file_content = template_file.read()
return Template(template_file_content)