本文整理汇总了Python中template.Template.define_vmethod方法的典型用法代码示例。如果您正苦于以下问题:Python Template.define_vmethod方法的具体用法?Python Template.define_vmethod怎么用?Python Template.define_vmethod使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类template.Template
的用法示例。
在下文中一共展示了Template.define_vmethod方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: testListVmethods
# 需要导入模块: from template import Template [as 别名]
# 或者: from template.Template import define_vmethod [as 别名]
def testListVmethods(self):
odd = lambda seq: [x for x in seq if x % 2 != 0]
Stash.LIST_OPS["sum"] = lambda seq: sum(seq, 0)
Stash.LIST_OPS["odd"] = odd
Stash.LIST_OPS["jumble"] = jumble
params = { "metavars": ("foo", "bar", "baz", "qux", "wiz", "waz", "woz"),
"people": [ { "id": "tom", "name": "Tom" },
{ "id": "dick", "name": "Richard" },
{ "id": "larry", "name": "Larry" } ],
"primes": (13, 11, 17, 19, 2, 3, 5, 7),
"phones": { "3141": "Leon", "5131": "Andy", "4131": "Simon" },
"groceries": { "Flour": 3, "Milk": 1, "Peanut Butter": 21 },
"names": [MyObject(x) for x in ("Tom", "Dick", "Larry")],
"numbers": [MyObject(x) for x in ("1", "02", "10", "12","021")],
"duplicates": (1, 1, 2, 2, 3, 3, 4, 4, 5, 5) }
context = Template().context()
context.define_vmethod("list", "oddnos", odd)
context.define_vmethod("array", "jumblate", jumble)
self.Expect(DATA, None, params)