From: Pulak P. (UAB) <Pul...@ua...> - 2001-08-20 12:46:21
|
Hi, I am tring to use Jython for a scripting application to configure a = External Device. The idea is to provide user the flexibility of writing scripts in = jython while the GUI and other aspects of external communications etc = are handled in Java. Once the GUI is ready and the communication class is instantiated the = control will be passes to a jython script.=20 The communication Object ( which is a java object) will be passes on = to the Jython script which will then call "Send(Command)" interface for = example.=20 To do I am doing the following Java side -------------- //jptComm object is already instantiated and setup. It has an interface = send(string). PythonInterpreter interp =3D new PythonInterpreter(); try{ interp.execfile(fileName); // where filename is the name of = jython script ( runscript.py) } catch( PyException except) { System.out.println("Error occured in exec file"); } try{ interp.exec("run(jptComm)"); // where the jptComm in the = communication object. //interp.exec("run(2)"); //instead if I pass builtin types = like int or string it works fine. } catch( PyException except) { System.out.println("Error occured in EXEC"); System.out.println(except.toString()); } } ________________________________________________________________________= __________ Jython side --------------- import java import jpitool.jpitoolCommunicator def run(jcp): print 'xyz' #jcp.send('ls') if __name__ =3D=3D '__main__': run(2) ________________________________________________________________________= _________ If I execute the Java code and call the run function from there with = communicator object as the argument it always gives me a "NameError" exception =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D Error occured in EXEC Traceback (innermost last): File "<string>", line 1, in ? NameError: jptComm =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D If i use any standard data type like int or string for eg " = interp.exec("run(2)") " it works fine. Can someone help. Any information on the same will be helpful. Regards, Pulak Piplani =C4S/UAB/S/MU Ericsson Utvecklings AB. Phone : +46 8 727 2559 ECN : 851 2559 |