from Cheetah.Template import Template
dummyUser={‘firstName‘:‘Harvey‘,‘lastName‘:‘liu‘}
dummyOrder={‘id‘:2}
definition = """Hello, $user.firstName.
Your number is $order.id."""
definition_new = Template(definition, searchList=[{‘user‘ : dummyUser,‘order‘ : dummyOrder}])Hello, $user.firstName. Your order (#$order.id) has shipped: #for $purchased, $quantity in $order.purchased.items(): $purchased.name: $quantity unit #if $quantity != 1 s #end if #end for打印结果为:
Widget, green: 50 unit s Widget, blue: 1 unit
原文:http://blog.csdn.net/magicharvey/article/details/19076773