Skip to content

Instantly share code, notes, and snippets.

@javisantana
Created June 14, 2011 18:09
Show Gist options
  • Select an option

  • Save javisantana/1025486 to your computer and use it in GitHub Desktop.

Select an option

Save javisantana/1025486 to your computer and use it in GitHub Desktop.
small templating languaje
import re
def template(text, vars):
def _t(v):
v = v.groups()[0]
return vars.get(v, '')
return re.sub('\{([^\}]*)\}', _t, text)
print template("hello, my name is {name}", {'name': 'javi'})
# please, do not use this code, instead you could use http://docs.python.org/library/string.html#template-strings
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment