1

I am trying to call python code from java file using Jython 2.7.2 with python files using version 3.9 but getting the error. Java code as below:

PythonInterpreter interpreter = new PythonInterpreter();
        interpreter.execfile("/src/main/java/com/example/demo/LeapYear.py");
        interpreter.set("year", 2020);
        PyObject retVal = interpreter.eval("LeapYear().check_leap_year(year)");
        System.out.println(retVal.toString());

My python code as below:

class Check_Leap_Year:

    def check_leap_year(self, year):
        if (year % 4) == 0:
            if (year % 100) == 0:
                if (year % 400) == 0:
                    print("{0} is a leap year".format(year))
                else:
                    print("{0} is not a leap year".format(year))
            else:
                print("{0} is a leap year".format(year))
        else:
            print("{0} is not a leap year".format(year))

1 Answers1

0

I faced with such problem. Solved just not to use python syntax 2.0

  • 1
    Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Dec 30 '22 at 13:25