better way than: myPage += 'more html' , ...
pinard at iro.umontreal.ca
Thu Jun 26 15:09:51 CEST 2003
> # renaming the append method makes it a bit easier on the eye.
> a = htmlPage.append # ah dynamic languages
> # using cStringIO should be the fastest approach
> import cStringIO
> io = cStringIO()
> a = io.write
> htmlDoc = io.getvalue()
Your usage of "should" is Interesting :-). I wonder what it really means;
either that you did not time it, or that you timed it and found it not to be
the fastest. I'm a big fan of the `.append'-based method, but would switch
to `cStringIO' if it was significantly faster. I guess that both methods
are roughly O(N), but would suspect the `cStringIO' might have a higher
start factor, making it less appealing for only a few short strings. Did
someone actually timed both methods compared, and got an opinion?
 And also given, for stylistic reasons, that the `io.close()' can be
spared. The first example does not explicitely empty `htmlPage'. But this
is likely an orthogonal issue and another debate.
François Pinard http://www.iro.umontreal.ca/~pinard
More information about the Python-list