python - How to convert multiple newlines in mako template to one newline? -


i using mako template python , trying generate text file using list python script. part of code shown below causing problem.

% compname in tpdob.scalar_modi:     ${compname[0]} ${compname[1]} ${compname[2]} ${compname[3]} % endfor 

i using code , output horrible.
here, have many lists in scalar_modi , printing them 1 one (each list has 4 values). problem is, there many newlines gets printed making output text file ugly. searched on net, unable find required solution. can please me out this?

comments on output:

with ${compname[0]} ${compname[1]} ${compname[2]} ${compname[3]} , getting:
1 42 gzb dli

14 23 tpty sre

32 55 puri ald


when using ${compname[0]} ${compname[1]} ${compname[2]} ${compname[3]} \, gives : 11 42 gzb dli14 23 tpty sre32 55 puri ald


, want like:
11 42 gzb dli
14 23 tpty sre
32 55 puri ald


and when using if-else conditions, getting more 2 newlines. can please me this. unable find solution in documentation :(

i had same problem, looks bug in mako templates windows. providing template string instead of file reference (as shown below) solved problem.

with open('code.template') f:     templatestr = f.read() template = mako.template.template(templatestr) 

Comments

Popular posts from this blog

javascript - Count length of each class -

What design pattern is this code in Javascript? -

hadoop - Restrict secondarynamenode to be installed and run on any other node in the cluster -