Search code examples
pythonmako

How can mako access the object name currently being rendered under Windows


I am new to mako, and have a question about the object model.

We are generating a template file via mako under Windows 7 through the render command, similar to

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

within the file being rendered, I want to access the objectname similar to the following pseudo code ...

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

Is this even possible?

Note: I can get it to generate output similar to the following

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

but I want the actual object name


Solution

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

    renders

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