Speed vs security vs compatibility over methods to do string concatenation in Python

Posted by Cawas on Stack Overflow See other posts from Stack Overflow or by Cawas
Published on 2010-05-07T22:01:30Z Indexed on 2010/05/07 22:08 UTC
Read the original article Hit count: 342

Similar questions have been brought (good speed comparison there) on this same subject. Hopefully this question is different and updated to Python 2.6 and 3.0.

So far I believe the faster and most compatible method (among different Python versions) is the plain simple + sign:

text = "whatever" + " you " + SAY

But I keep hearing and reading it's not secure and / or advisable.

I'm not even sure how many methods are there to manipulate strings! I could count only about 4: There's interpolation and all its sub-options such as % and format and then there's the simple ones, join and +.

Finally, the new approach to string formatting, which is with format, is certainly not good for backwards compatibility at same time making % not good for forward compatibility. But should it be used for every string manipulation, including every concatenation, whenever we restrict ourselves to 3.x only?

Well, maybe this is more of a wiki than a question, but I do wish to have an answer on which is the proper usage of each string manipulation method. And which one could be generally used with each focus in mind (best all around for compatibility, for speed and for security).

Thanks.

© Stack Overflow or respective owner

Related posts about python

Related posts about string-manipulation