Hi all, first post so hopefully I'm in the correct place.

I'm new to python/jython and am currently trying to write a hot-deploy script, in short its working, however I am now making it for mulitple applications. I'm really struggling to get the path to a JAR archive into a list. I have a property file that contains the following:

undeployapplication.02-console.name=02-console
undeployapplication.02-console.path=/opt/app/stage/apps/02-console.ear
undeployapplication.02-console.target=cluster

In python I am creating a list and trying to append it with the .path part of the property file. I know these values are working because I can bind them into a string and print it to the screen. I can also hardcode the path into a string and that imports into the list as well. However with the following it falls over with a " TypeError: __add__ nor __radd__ defined for these operands" error.

def unDeployApps():
    unApps=splitMap(props,'undeployapplication.')
    for unApp in unApps.keys():
        properties=unApps[unApp]
        unDepSuccess=[]
        unDepSuccess.append("hello")
        unDepSuccess.append("Test")
        unDepSuccess.append("Bye")
# Test to prove list is ok
        print unDepSuccess
        strTest=properties["path"]
# This also prints the correct path
        print "Printing strTest " + strTest
        print "Adding strTest to Array " + `unDepSuccess`
# This is where is falls over
        unDepSuccess.append(strTest)
        print "Printing unDepSuccess " + unDepSuccess

Screen output:

[java]
[java] Printing strTest /opt/app/stage/dsb-apps/02-console.ear
[java] Adding strTest to Array
[java] File "/opt/app/stage/redeployment/redeploy.py", line 136, in ?
[java] File "/opt/app/stage/redeployment/redeploy.py", line 69, in unDeployApps
[java] TypeError: __add__ nor __radd__ defined for these operands

I'm probably making a very basic error somewhere but if anyone can point me in the right direction it'd be appreciated.

Many thanks, hopefully I can feed back into this forum when I actually know what I'm doing :)

Dave

Edited 6 Years Ago by ds2000: n/a

I'm sorry to hear that you have to work with Jython. My condolences. That being said, why don't you insert a print type(strTest) to see if it's actually being presented as a string.

Thanks, it seems it is:

[java] org.python.core.PyString

I've heard it a complete pain in the backside, have had a couple of good java devs look at it with me as well :)

TypeError: __add__ nor __radd__ defined for these operands

The error could be here because of backticks
print "Adding strTest to Array " + `unDepSuccess`
Also, you can not concatenate a string and a list (I'm assuming it is a list because you append to it).
print "Printing unDepSuccess " + unDepSuccess
print "Adding strTest to Array " + `unDepSuccess`

Use
print "Printing unDepSuccess ", unDepSuccess

Edited 6 Years Ago by woooee: n/a

This article has been dead for over six months. Start a new discussion instead.