Last active
January 15, 2021 12:28
-
-
Save simonthompson99/74fde2ff66ae47dbf77688aacb333920 to your computer and use it in GitHub Desktop.
[Read template file] Read a text file and return it as a Template object #python
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 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) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment