Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/templates/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 避免在Mako块/标记后出现额外的换行符_Python_Templates_Removing Whitespace_Mako - Fatal编程技术网

Python 避免在Mako块/标记后出现额外的换行符

Python 避免在Mako块/标记后出现额外的换行符,python,templates,removing-whitespace,mako,Python,Templates,Removing Whitespace,Mako,我有一个Mako模板,其中有一些块,如下所示: <%page /> % for x in ["one", "two", "three"]: <% y = ''.join(reversed(x)) %> ${x} backwards is ${y} % endfor one backwards is eno two backwards is owt three backwards is eerht 我希望输出如下所示: <%page /> % for

我有一个Mako模板,其中有一些块,如下所示:

<%page />
% for x in ["one", "two", "three"]:
<%
    y = ''.join(reversed(x))
%>
${x} backwards is ${y}
% endfor
one backwards is eno
two backwards is owt
three backwards is eerht
我希望输出如下所示:

<%page />
% for x in ["one", "two", "three"]:
<%
    y = ''.join(reversed(x))
%>
${x} backwards is ${y}
% endfor
one backwards is eno
two backwards is owt
three backwards is eerht
除了在每个块和标记后手动添加
\
之外,还有其他方法可以做到这一点吗


有一个类似的问题,但它已经9年了,公认的答案是对Mako输出进行后处理。对于我的用例来说,这不是一个很好的解决方案,因为我希望在输出中保留除了来自块/标记的空行之外的空行,并且确定哪些是空行是非常重要的。

尝试将文件的行尾从CRLF更改为LF

至少这对我有用

不过,我的问题有点不同。如果您的额外行来自
%>
后面的行,我认为\是唯一的解决方案