<div class="gmail_quote">On Mon, Apr 18, 2011 at 5:17 PM, Rance Hall <span dir="ltr">&lt;<a href="mailto:ranceh@gmail.com">ranceh@gmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
Ok so I know what I am doing is deprecated (or at least poor form) but<br>
the replacement must be awkward cause I&#39;m not getting it.<br>
<br>
<br>
so this is in a cli based program designed to print status messages to<br>
the terminal on a linux box.<br>
<br>
pseudo code:<br>
<br>
<br>
message = &quot;Bah.&quot;<br>
<br>
if test:<br>
   message = message + &quot; Humbug!&quot;<br>
<br>
print(message)<br>
<br>
end pseudo code<br>
<br>
<br>
I&#39;m sure this is not the way we are supposed to augment strings like this.<br>
<br>
maybe there is string.append() method or something I should be using instead?<br>
<br>
In my case the optional extra parts are always at the end of the<br><blockquote style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;" class="gmail_quote">
current value of the string.<br></blockquote>
<br></blockquote><div><br>The reason it&#39;s deprecated is because it&#39;s SLOW - since strings are immutable, there&#39;s a lot of extra copying going on behind the scenes.  If this code were inside a loop, being run lots and lots of times, this would quickly become one of the bottlenecks of your program.  However, in the example you&#39;ve given, I&#39;m not sure it would make an important difference - as slow as string concatenation is, it&#39;s still a heck of a lot faster than the human operator!<br>
<br>If you just want to have a status update for your user - like a progress bar - you could simply print one string at a time and not store the result.  (i.e. if you just want to display a line of dots to indicate activity, you don&#39;t need to store the full number of dots - just print one at a time - without newlines - and forget about it.)<br>
<br>If, on the other hand, you always want to have access to the full string AND you want to print it along the way, then try a list.  Lists are awesome! <br><br><blockquote style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;" class="gmail_quote">
message = [&#39;Bah&#39;] # message is a list, which currently contains one item: &#39;Bah&#39;<br>for x in range(10):<br>    message.append(str(x))  # append a string (&#39;0&#39;, &#39;1&#39;, etc.) to the list<br>    print &quot; &quot;.join(message)  # print the contents of the list, separated by spaces<br>
</blockquote><br>That&#39;s if you want to do this in a loop.  If you have a set number of items to display, then string formatting is your friend:<br><br><blockquote style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;" class="gmail_quote">
message = &#39;The %s in %s stays mainly in the %s&#39; % (&#39;rain&#39;, &#39;Spain&#39;, &#39;plain&#39;)<br></blockquote><br></div></div>