Quickest way to build a long string?

Aahz Maruch aahz at panix.com
Thu Oct 12 15:55:50 EDT 2000


In article <u3abuskq55oiugpuafh3fqdkl45s7am6vh at 4ax.com>,
Dale Strickland-Clark  <dale at out-think.NOSPAM.co.uk> wrote:
>
>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

I would use the % operator to build up the small strings (as someone
else mentioned, "<td>%s</td>" % value is extremely handy) and either
string.join() or cStringIO.  I usually use string.join() unless some
other part of my program wants a file object.
-- 
                      --- Aahz (Copyright 2000 by aahz at pobox.com)

Androgynous poly kinky vanilla queer het    <*>     http://www.rahul.net/aahz/
Hugs and backrubs -- I break Rule 6

"Isn't it interesting that the same people who laugh at science fiction
listen to weather forecasts and economists?" -- Kelvin Throop III



More information about the Python-list mailing list