line是模板中一行的内容,类似: {{x}}testinfo{{x+10}}
x=10时,模板输出: 10testinfo20
x = 10 splits = re.split(r'\{\{(.*?)\}\}', line) for i in range(1, len(splits), 2): splits[i] = str(eval(splits[i])) print ''.join(splits)