I am trying to write a program about a .py extend a java interface, just like an example on IBM developerworks.
But I got a problem like:
AttributeError: read-only attr: cardID
But the strange thing is if I rename the cardID to cardNum,it works. Here my code:
CardInfo.py
from com.jyt import CardInfo
class CardInfo(CardInfo):
def __init__(self):
self.cardName = "Dark Magician"
self.cardID = "888"
def getName(self):
return self.cardName
def getCardID(self):
return self.cardID
def setID(self,newID):
self.cardID = newID
and the java interface:
public interface CardInfo {
public String getCardID();
public String getName();
public void setID();
}
and the java file
Object javaObject;
PythonInterpreter interpreter = new PythonInterpreter();
// PySystemState sys = Py.getSystemState();
interpreter.execfile("./res/CardInfo.py");
interpreter.exec("cardInfo=CardInfo()");
PyObject pyObject = interpreter.get("cardInfo");
pyObject.invoke("setID",new PyString("12345"));
try{
javaObject = pyObject.__tojava__(CardInfo.class);
CardInfo cardInfo = (CardInfo)javaObject;
System.out.println(cardInfo.getCardID());
System.out.println(cardInfo.getName());
}catch(Exception e){
e.printStackTrace();
}
anyone knows how to solve this?