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

Max M maxm at mxm.dk
Wed Jun 25 17:44:28 EDT 2003


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

Actually there are yet a few twists to put on this.

# renaming the append method makes it a bit easier on the eye.

htmlPage=[]
a = htmlPage.append # ah dynamic languages

a("<html><header></header><body>")
a("more html")
....
a("more html")
....
a("<\body><\html>")
htmlDoc="\n".join(htmlPage)


# using cStringIO should be the fastest approach

import cStringIO
io = cStringIO()
a = io.write

a("<html><header></header><body>\n")
a("more html\n")
....
a("more html\n")
....
a("<\body><\html>\n")
htmlDoc = io.getvalue()
io.close()


regards Max M





More information about the Python-list mailing list