From: Ype K. <yk...@xs...> - 2001-02-11 11:23:25
|
Jaroslav, >... >It works but it is significantly slow, probably because an template is >parsed every time the renderFace() method is called. I am looking for >more efficient solution, but Jython's documentation is very spare >about this. > ... >***template.py*** >out.write(""" ><html> ><head> ><title>Test</title> ></head> ><body> ><h1>Test</h1> >""") >out.write("<p>name is {" + foo.name + " }\n") >out.write(""" ></body> ></html> >""") >***end sources*** Don't embed. Try using the % operator for strings: "<p>name is {%s }\n")" % foo.name Evt. built the left hand operator dynamically. In case you need multiple substitutions use the % operator as: "Some text for %s, another text for %s, enfin." % ("flying the circus" , "monty") You can also built the right hand side dynamically. Alternative: In case you only need to concatenate strings, and some of these vary, put them all in a list, manipulate the list as necessary and then use join: yourListOfStrings[indexOfVaryingString] = newVaryingString theWholeText = ''.join(yourListOfStrings) You might preconcatenate fixed strings as much as possible within this list. Speed improvement should be dramatic either way. Have fun, Ype |