java与jython结合使用总结

  1. java中要配置python.pathSyste.setProperty("python.path","D:\\path")

  2. python中私有变量以双下划线开头

  3. java实例化python类

    PythonInterpreter interpreter = new PythonInterpreter(); 
    interpreter.exec("from " + packName + " import " + clsName); 
    PyObject pyObject = interpreter.get(clsName); 
    PyObject newObj = pyObject.__call__(); 
    // Call __tojava__ method on the new object along with the interface name 
    // to create the java bytecode 
    javaInt = newObj.__tojava__(JavaInterface.class);
    
  4. python中对已定义的方法进行拦截

    class MyAop(object): 
    
        __flag=False
    
        def testMethod(self,param): 
            print "this in the parent......"
    
        def __getattribute__(self,attName): 
            if attName=="testMethod": 
                if self.__flag==False: 
                    return self.aop 
                else: 
                    self.__flag=False 
            return object.__getattribute__(self,attName) 
    
        def aop(self,param): 
            print param self.__flag=True self.testMethod(param)
    

你可能感兴趣的:(java与jython结合使用总结)