简体   繁体   English

#define为Python的模板

[英]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? 我应该使用许多模板框架中的哪一个才能在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;

I looked into Jinja2 as Simeon suggested. 我按照Simeon的建议研究了Jinja2。 It looks very handy, and has macros too! 它看起来非常方便,并且也具有宏! http://jinja.pocoo.org/docs/dev/templates/#macros http://jinja.pocoo.org/docs/dev/templates/#macros

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM