Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Best Python templating library to facilitate code generation [closed]

Instead of me spending the next day (or year) reading about them all, are there any suggestions for templating engines that I should look into in more detail?

like image 442
taudep Avatar asked Mar 04 '09 22:03

taudep


People also ask

How do you create a code generator in Python?

You can create a generator model with the YAKINDU Statechart generator model wizard by selecting File → New → Code generator model. The code generation is performed automatically whenever the statechart or the generator file is modified. See also chapter Running a generator for more information.

What is Mako Python?

Mako is a template library written in Python. It provides a familiar, non-XML syntax which compiles into Python modules for maximum performance. Mako's syntax and API borrows from the best ideas of many others, including Django templates, Cheetah, Myghty, and Genshi.

What is templating in Python?

Templating, and in particular web templating is a way to represent data in different forms. These forms often (but not always) intended to be readable, even attractive, to a human audience.

Is a template engine for Python?

Jinja, also known and referred to as "Jinja2", is a popular Python template engine written as a self-contained open source project. Some template engines, such as Django templates are provided as part of a larger web framework, which can make them difficult to reuse in projects outside their coupled library.


2 Answers

Best suggestion: try them all. It won't take long.

My favourite: Jinja2 (by a mile)

It has decent syntax, can trace errors through it, and is sandboxable.

like image 194
Ali Afshar Avatar answered Oct 11 '22 21:10

Ali Afshar


If you're doing code generation, you might find Cog useful - it's specifically for code generation, rather than being a generally applicable templating language.

like image 24
babbageclunk Avatar answered Oct 11 '22 21:10

babbageclunk