In a use case for autogenerating code from a Mako template, I'd like to have a nice syntax to remove leading whitespace (similar to removing newlines with \
at the end of a line).
The following code
from mako.template import Template
# 1) Bad
print(Template(r'''
void myfunction(\
%for arg_name, arg_type in arguments:
${', ' if loop.index else ''}${arg_type} ${arg_name}\
%endfor
)
''').render(arguments=[('string', 'a'), ('int', 'b')]))
# 2) Good but ugly
print(Template(r'''
void myfunction(\
%for arg_name, arg_type in arguments:
<% %>${', ' if loop.index else ''}${arg_type} ${arg_name}\
%endfor
<%%>)
''').render(arguments=[('string', 'a'), ('int', 'b')]))
will print these results:
void myfunction( a string , b int )
void myfunction(a string, b int)
I want the latter output — so is there a nicer syntax while still keeping my Mako template nicely indented? My solution with an empty <% %>
isn't exactly beautiful.