Skip to content

Instantly share code, notes, and snippets.

@deeagle
Created November 27, 2016 19:34
Show Gist options
  • Save deeagle/854b501fac22cbdf9524d7c4a91defae to your computer and use it in GitHub Desktop.
Save deeagle/854b501fac22cbdf9524d7c4a91defae to your computer and use it in GitHub Desktop.
Simple template substitution of plain text and python3
#!/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)
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