jython and concatenation of strings
Steven Bethard
steven.bethard at gmail.com
Mon Dec 13 12:24:52 EST 2004
Jan Gregor wrote:
> Hello
>
> 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 !!!
>
> What's alternative way to do that ? (similiar parts of my code are terribbly
> slow and such simple solution as above didn't help).
I don't use Jython, but are you not able to do something like:
string_list = []
for ... in ...:
...
string_list.append(...)
...
string = ''.join(string_list)
This is the usual Python idiom and is usually faster than the += idiom.
Note too that +ing strings in Java also has this problem -- hence
StringBuffer or whatever it's called.
Steve
More information about the Python-list
mailing list