better way than: myPage += 'more html' , ...

Gobo Borz goboborz at yahoo.com
Wed Jun 25 12:20:27 EDT 2003


Hi everyone,

I have a python cgi program that uses print statements to write html. 
The program has grown, and for reasons I won't bore you with, I need to 
build the page in a string and "print" it at once.

I remember reading somewhere that building the string with successive 
"+=" statements is inefficient, but I don't know any alternatives, and 
my search attempts came up empty. Is there a better, more efficient way 
to do it than this:

#---------------------------------
htmlPage = "<html><header></header><body>"
htmlPage += "more html"
...
htmlPage += "even more html"
...
htmlPage += "</body></html>"
print htmlPage
#-------------------------------------

Thanks, Gobo





More information about the Python-list mailing list