For a specific usage I made a very simple template engine in Python, to display value. The code:import reclass Template(object):    A simple template engine support only the substitute of variable    def __init__(            self, delimiter_start='[', delimiter_end=']',            identifier=r'^[^\d\W]\w*$'):        To initialize the template class.        @param delimiter_start: To specify the delimiter start (default [)        @type param: str        @param delimiter_end: To specify the delimiter stop (default ])        @type param: str        @param identifier: Identifier for variable name (default ^[^\d\W]\w*$)        @type param: str                self.delimiter_start = delimiter_start        self.delimiter_end = delimiter_end        self.identifier = re.compile(identifier, re.UNICODE)    def substitute(self, string, template={}):        To substitute the string.        @param string: The string to substitute        @type string: str        @param template: The template        @type string: dict        @return:  The string substitute        @rtype :  str        @raise ValueError:  Identifier is not valid                words = string.split( )        for index, word in enumerate(words):            if word.startswith(self.delimiter_start) \                    and word.endswith(self.delimiter_end):                        word_without_delimiter = word[1:-1]                        result = re.match(                            self.identifier, word_without_delimiter)                        if result is None:                            raise ValueError(                                'The identifier is not a valid identifier')                        if word_without_delimiter not in template:                            continue                        words[index] = '{value}'.format(                            value=template[word_without_delimiter])        return ' '.join(words)And the test:import unittestfrom passport.passport import Templateclass TemplateTestCase(unittest.TestCase):    To test the template    def setUp(self):        self.template = Template()    def test_simple(self):        string = To try only [var] it's display correctly        result = self.template.substitute(string, {'var': 'if'})        self.assertEqual(To try only if it's display correctly, result)    def test_multiple_variable(self):        string = To try only [var] it's [other_var] correctly        result = self.template.substitute(string, {            'var': 'if', 'other_var': 'display'})        self.assertEqual(To try only if it's display correctly, result)    def test_one_word(self):        string = '[var]'        result = self.template.substitute(string, {'var': 'Try'})        self.assertEqual('Try', result)    def test_without_template(self):        string = 'Try without a template in string no substitute'        result = self.template.substitute(string, {'var': 'Try'})        self.assertEqual(string, result)    def test_with_other_delimiter(self):        template = Template(delimiter_start='{', delimiter_end='}')        string = To try only {var} it's display correctly        result = template.substitute(string, {'var': 'if'})        self.assertEqual(To try only if it's display correctly, result)    def test_key_is_not_present(self):        string = To try only [var] it's display correctly        result = self.template.substitute(string)        self.assertEqual(To try only [var] it's display correctly, result)    def test_with_invalid_identifier(self):        string = '[42var]'        with self.assertRaises(ValueError):            self.template.substitute(string, {'42var': 'Try'})New methods will be added soon, for example add some take a file and not a string.
A simple template engine to display value
python;reinventing the wheel;template