jython and concatenation of strings

Jan Gregor gregor.jan at NOSPAMquick.cz
Tue Dec 14 06:05:50 EST 2004


Ok, thanks. I didn't think that += operator is nondestructive operation
- but strings are immutable so this makes sense.

On 2004-12-13, Diez B. Roggisch <deetsNOSPAM at web.de> wrote:
>>  I found that price of += operator on string is too high in jython. For
>>  example 5000 such operations took 90 seconds (i generated html copy of
>>  table with 1000 rows and 5 columns). Generation of row data into separate
>>  string and joining after lead to time 13 seconds !!!
>
> Its generally not recommended to use simple string concatenation for
> building larger strings - neither in python nor in java/jython.
>
> afaik there are two solutions to this: The java-way and the jython way:
>
> java: Use StringBuffer
> python: use a list, and append the strings to that. Then, when you want the
> result, do
>
> "".join(stringlist)
>



More information about the Python-list mailing list