From: Jeremy H. <je...@al...> - 2003-03-07 21:42:46
|
On Fri, 2003-03-07 at 12:53, Moyer, Todd wrote: > I was putting together a string representation of a Table object I > developed. One of my most common uses for this is taking the output of an > SQL select, which can get quite large. I had been doing a lot of string > concatination (string = string + "foo"). Needless to say, this got really > slow when the tables were big: 5,000 rows was taking almost a minute. I > reimplemented using the Java StringBuffer's "append" method. Execution time > dropped to about 1 second. > > Using the Java object in my Jython code was easy; I can post it if anyone > wants to see it. However, is there pure Jython way to do this that I'm > overlooking? If not, is this something worth adding to the language? The typical Python idiom is to accumulate the strings in a list, then use the join() string method. L = [] L.append("1") L.append("2") L.append("3") s = "".join(L) print s "123" Jeremy |