Is there a defacto template application for Python?
I am trying to auto generate C code for use in unit tests from python
My original approach using print statements is very clunky and error prone
It struck me that a template application such as those used in web app development might be a more elegant solution
My initial research seems to suggest Cheetah is a good option, however there seem to be many potential options
My requirements would be that it is reliable and simple - would Cheetah represent 'best practice' for this sort of application?
While there are many standalone and powerful template engines in Python there is one in Python standard library.
There is Template class in string module that implements PEP 292 "Simpler String Substitutions" that is very easy to learn and use. Personally I prefer to use this in my unit tests.
I don't think there's such a thing as a defacto templating system for Python, there's quite a wide variety of them.
Personally, I haven't tried out Cheetah yet, but had some very successful experiences with Jinja2, and there's also alot of buzz around Mako. Both of these are more focused on generating HTML code, but there's really no impediment on using them for anything else. I would go with the one that provides the most comfortable syntax for what you're used to.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With