mako如何访问当前在Windows下呈现的对象名称

时间:2011-07-13 18:10:25

标签: python mako

我是mako的新手,并对对象模型有疑问。

我们通过mara在Windows 7下通过渲染命令生成模板文件,类似于

out.write(self.objectname.render(...))

在正在呈现的文件中,我想访问类似于以下伪代码的对象名...

<%namespace name="mapping" module="objtool.mapping" />
<%!
import os
import time
%>\
======================================================
== this file is being rendered from $(object.name)
======================================================

这甚至可能吗?

注意:我可以让它生成类似于以下内容的输出

this file is being rendered from <mako.template.Template object at 0x02F48990>

但我想要实际的对象名称

1 个答案:

答案 0 :(得分:0)

<%namespace name="mapping" module="objtool.mapping" />
<%!
import os
import time
%>\
======================================================
== this file is being rendered from ${os.path.basename(self.name)}
======================================================

呈现

======================================================
== this file is being rendered from poco_custom.cs
======================================================