newbie: concatenate literals (using jython)

Fredrik Lundh fredrik at pythonware.com
Thu Dec 22 13:23:07 EST 2005


davidmichaelkarr at gmail.com wrote:

> I'm using Jython (actually WebLogic WLST), and trying to do something
> really simple.  I want to create a string from two function calls and a
> literal, like:
>
>   serverport = server.getListenAddress() + ':' + server.getListenPort()
>
> This complains:
>
> TypeError: __add__ nor __radd__ defined for these operands
>
> I've looked at various references, and this seems like the way I'm
> supposed to do this, but I'm obviously missing something.  Note that
> "getListenPort()" returns an int.  Is that a problem?

yes.  python's string concatenation operator doesn't convert things nilly-
willy (should "1"+1 be 2 or "11" ?).  to convert an object to a string, use
str(obj).  see this tutorial section for more info:

http://docs.python.org/tut/node9.html#SECTION009100000000000000000

</F>






More information about the Python-list mailing list