Efficient String Concatenation in Python
If you've ever created long strings in Python, you may have noticed that string concatenation is slow. There's a great site that tries out the different methods for concatenating strings in python at
http://www.skymind.com/~ocrow/python_string/. In a nutshell, I've found this one works best for my operations:
def method5():
# Example that concatenates numbers
from cStringIO import StringIO
file_str = StringIO()
for num in xrange(loop_count):
file_str.write(`num`)
return file_str.getvalue()
0 comments:
Post a Comment