java 文件“__pyclasspath__/site.py“,第178行文件=系统标准错误)语法错误:输入“=”不匹配,需要RPAREN

nwo49xxi  于 2023-01-01  发布在  Java
关注(0)|答案(1)|浏览(72)

我尝试使用Jython 2.7.2从java文件调用python代码,使用版本3.9调用python文件,但出现错误。Java代码如下:

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());

我的python代码如下:

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))
kpbwa7wx

kpbwa7wx1#

我遇到过这样的问题。解决了只是不使用python语法2.0

相关问题