Quickest way to build a long string?
Steve Holden
sholden at holdenweb.com
Thu Oct 12 09:27:19 EDT 2000
Dale Strickland-Clark wrote:
>
> I'm building a web page (table) from a whole bunch a database fields.
> Each field needs the table row and cell tags added around it and then
> be appended to the results so far.
>
This may be a dumb question, but why are you generating the string
instead of writing it to the output stream? Is this what your web
server requires?
> String operations of this type tend to be memory thrashers so I was
> wondering if anyone had conducted any tests to see which of the
> approaches available might be the most efficient.
>
> 1. multiple string concetenation. (html = html + cell)
> 2. build list of components then use join at the end to make a string
> 3. something even cleverer
>
Well, there's also the % operator, which tends to be a bit more efficient
at constructing strings where most of the information is fixed but some
variable substitution is needed.
e.g.:
"<td><b>%s</b></td>" % (cell_contents,)
> Thanks for any info.
> Dale Strickland-Clark
> Out-Think Ltd
> Business Technology Consultants
regards
Steve
--
Helping people meet their information needs with training and technology.
703 967 0887 sholden at bellatlantic.net http://www.holdenweb.com/
More information about the Python-list
mailing list