Thanks Cliff. Not to belabor this point - clearly it's just something I'll have to get used to - but isn't the choice of the "+" as the concatenation operator part of the problem here? A more "explicit" choice would have been an "append()" function, would it not? Or at least a non-ambiguous character.<br><br>Obviously python *does* know that I'm concatenating, not adding, due to the type of the LH object, and it would save me a lot of time if I didn't have to explicitly convert my objects to strings.<br><br>Any rule can be abused...<br><br>- Michael<br><br><b><i>"J. Clifford Dyer" <jcd@sdf.lonestar.org></i></b> wrote:<blockquote class="replbq" style="border-left: 2px solid rgb(16, 16, 255); margin-left: 5px; padding-left: 5px;"> On Tue, Nov 13, 2007 at 07:15:06AM -0800, Michael Pelz Sherman wrote regarding why no automatic conversion in string concatenation?:<br>> <br>> As a Java & PHP developer, I find it kind of annoying that I have to<br>>
explicitly convert non-string variables to strings when concatenating<br>> them, especially when python is quite capable of doing the conversion<br>> automatically.<br>> i.e.:<br>> >>> myBool = True<br>> >>> print myBool<br>> True<br>> >>> print "myBool is " + myBool<br>> Traceback (most recent call last):<br>> File "<stdin>", line 1, in <module><br>> TypeError: cannot concatenate 'str' and 'bool' objects<br>> >>> print "myBool is " + str(myBool)<br>> myBool is True<br>> Can anyone explain why this is so? <br><br>Because python doesn't know if '1' + 1 should equal 2 or '11' and would rather you mad that decision. Should it be different than 1 + '1'? <br><br>or to put it more succinctly, because "explicit is better than implicit."<br>In fact, I think it's more often the case that I have string data that I need to treat as integers than the other way around
(input from stdin and textfiles for example).<br><br>> Are there any plans to change this<br>> in python 3000?<br><br>I hope not, and I don't think so.<br><br>> Thanks,<br>> - Michael<br><br>No problem. <br><br>Cheers,<br>Cliff<br><br></module></stdin></blockquote><br>