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

Gobo Borz goboborz at yahoo.com
Wed Jun 25 20:52:02 CEST 2003


Thanks Alan, Anthony, and Andy!  B's thru Z's need not respond, I have 
my answer.

--Gobo


Gobo Borz wrote:
> 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