better way than: myPage += 'more html' , ...
Fredrik Lundh
fredrik at pythonware.com
Thu Jun 26 11:02:53 EDT 2003
Adrien Di Mascio wrote:
> I've a made a quite basic test on these methods :
>
> /snip/
>
> def write_thousands_join(self, char):
> """Writes a 100000 times 'char' in a list and joins it
> """
> str_list = []
> for index in range(100000):
> str_list.append(char)
>
> return ''.join(str_list)
no time to repeat your tests, but
def write_thousands_join(self, char):
"""Writes a 100000 times 'char' in a list and joins it
"""
str_list = []
append = str_list.append # bind method to local variable
for index in range(100000):
append(char)
return ''.join(str_list)
"should" be slightly faster.
also note that the results "may" differ somewhat if you append strings
of different lengths (mostly due to different overallocation strategies;
or maybe they're not different anymore; cannot remember...)
I always use join, but that's probably because that method is more likely
to run code that I once wrote. Never trust code written by a man who
uses defines to create his own C syntax ;-)
</F>
More information about the Python-list
mailing list