Skip to content

Instantly share code, notes, and snippets.

@niharika88
Last active October 10, 2018 20:50
Show Gist options
  • Select an option

  • Save niharika88/8eb8ecd430729f6caa647804bee1e011 to your computer and use it in GitHub Desktop.

Select an option

Save niharika88/8eb8ecd430729f6caa647804bee1e011 to your computer and use it in GitHub Desktop.
The function called populate_template which takes in a template string e.g. " Hello {!first_name} - How are you?" and a hash of fields e.g { "first_name" : "John" } as arguments and returns the template string with the fields inserted in the correct place. It takes in 2 arguments: - template (String) - fields (hash / dictionary)
import re
def populate_template(template, fields= {}):
for key, value in fields.items():
if template.find(key):
template_new = re.sub(key, fields[key], template)
return template_new
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment