Search code examples
pythontemplatesmacrostemplate-engine

Templates that #define for Python


Which of the many templating frameworks should I use to be able to use simple macros like this in Python? Basic macros seem to be all I need, and the amount of frameworks available is overwhelming.

#define R(a,b,c,k) as b ^= (a + c) << k
R(x[ 0], x[ 4], x[12], 7)
R(x[ 5], x[ 9], x[ 1], 7)

It would resolve into something like this (math-code):

x[ 4] ⊕= (x[ 0] ⊞ x[12])<<<7;    
x[ 9] ⊕= (x[ 5] ⊞ x[ 1])<<<7;

Solution

  • I looked into Jinja2 as Simeon suggested. It looks very handy, and has macros too! http://jinja.pocoo.org/docs/dev/templates/#macros