Created
November 27, 2016 19:34
-
-
Save deeagle/854b501fac22cbdf9524d7c4a91defae to your computer and use it in GitHub Desktop.
Simple template substitution of plain text and python3
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
#!/usr/bin/python3 | |
from string import Template | |
# open the file | |
filein = open('SimpleTemplate.tpl') | |
# read it | |
src = Template(filein.read()) | |
# document data | |
hello_to = "Henry" | |
my_name = "Hubbert" | |
d = {'hello_to' : hello_to, 'my_name' : my_name} | |
# do the substitution | |
result = src.substitute(d) | |
print(result) |
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
Hello $hello_to, | |
what's up with you? | |
King regards $my_name |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment