【发布时间】:2013-09-03 19:25:24
【问题描述】:
我有一个变量 myvariable,我想在 Mako 模板中使用它。我希望能够在对其进行任何操作之前以某种方式检查其类型。检查这类信息的语法是什么?我知道 python 有 typeof 和 instanceof,但是在 Mako 中是否有一些等价物或者你会怎么做?
伪代码如下:
% if myvariable == 'list':
// Iterate Throuh the List
%for item in myvariable:
${myvariable[item]}
%endfor
%elif variabletype == 'int':
// ${myvariable}
%elif myvariable == 'dict':
// Do something here
【问题讨论】: