I'm trying to set up an object instance that will provide values to the Cheetah3 text templating engine.
This is my text template script...
#filename: py_text_template.py
from traits.api import String, Range
from traits.api import HasTraits
from loguru import logger
from Cheetah.Template import Template
class Info(HasTraits):
keyword_integer = Range(value=0, low=1, high=60)
keyword_string = String(value="snack", regex=r"^\w+")
@logger.catch(onerror=lambda _: sys.exit(1))
def generate_text_template():
myinfo = Info(keyword_integer=10, keyword_string="snack-attack")
t = Template("On the first $myinfo.keyword_string, my true love")
print(t)
generate_text_template()
I expected to use the myinfo
instance of the Info()
class to populate the Template
, but I get the following error...
Cheetah.NameMapper.NotFound: cannot find 'myinfo'