search for a string?

cheesecake vigenereNOviSPAM at leland.stanford.edu.invalid
Mon Jun 5 05:28:53 EDT 2000


In article <8h6na4$ql7$1 at nntp9.atl.mindspring.net>, David
Broadwell <"dbroadwell"@spam.mindspring.com (remove spam.)>
wrote:
>>
>>     OldString = File.read() + OldString
>>
>>     I perfer, though: OldString = "%s %s" % (File.read
(),OldString)
>>
>The second once certianly looks more .. programmer. Now which
is more
>efficent? (faced with to apparenly equal choices) and why?

As I understand it, using format strings is much more efficient
for combining many strings, even for concatenating just three
strings because str1 + str2 + str3 performs too many
allocations, something like doing (str1 + str2) + str3,
whereas "%s%s%s" % (str1, str2, str3, ) only allocates one
result string.

I prefer using the %s method even for 2 strings because I can
decide later to add another string without having to change my
code for efficiency. I'm not sure which method is more efficient
for 2 strings.

I just tried to look up where I read a comparison between the
two methods, and I couldn't find it, so I could be imagining
things. Can somebody maybe confirm this?

TD


* Sent from RemarQ http://www.remarq.com The Internet's Discussion Network *
The fastest and easiest way to search and participate in Usenet - Free!




More information about the Python-list mailing list