Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8718337
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T06:31:13+00:00 2026-06-13T06:31:13+00:00

I am trying to write a program about a .py extend a java interface,

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T06:31:14+00:00Added an answer on June 13, 2026 at 6:31 am

    This is just a guess (can’t test it right now because I’m not on my own pc), but your problem is probably related to the (somewhat underdocumented) fact that jython generates property accessors for javas getter/setter methods, which clash with your attribute names and thus shadow your actual attribute.

    If my hypothesis is correct, the problem in this case is that you have a getter method which has the same name (minus the get part) as the attribute. Jython sees the method and generates a property for it, which is read-only because there is no matching setter method.

    It may be that you could fix this by just renaming your setID method to setCardID so jython correctly interprets the attribute as writable. If this doesn’t work for some reason, one of the following should definitely work:

    • rename the attribute to something else, like self.myCardID
    • alternatively, rename the method to something else, like getID

    Both of these solutions should cause the attribute to no longer be shadowed by the property accessor.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to write a program to analyze Java source code, for example,
I'm trying to write a program in Java that uses osql to generate a
Im making a program about the game Go and im trying to write some
I am trying to write a program to collect security information about a file
For Pi Day, I am trying to write a Java program that tries to
i ma trying to write a program where about the payments of employees and
I am trying to write a program to analyze emotional expressions like tears. As
I am trying to write a simple program about UDP Connections to learn about
I am trying to re-write a program in C to java. I have no
I am currently trying to write a program to store data about people into

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.