Created
June 14, 2011 18:09
-
-
Save javisantana/1025486 to your computer and use it in GitHub Desktop.
small templating languaje
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
| 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