From: Ype K. <yk...@xs...> - 2002-02-09 08:38:06
|
John, >quick question with embedding jython.... in the following example >(from the embedding 'tutorial' at jython.org) >how do I access MyClass from within the python code? > >import org.python.util.PythonInterpreter; >import org.python.core.*; > >public class SimpleEmbedded { > public static void main(String []args) throws PyException > { > PythonInterpreter interp = new PythonInterpreter(); <snip> > // how do I do this? > // interp.exec("MyObject.doSomething()"); <snip> > } >} >class MyClass >{ > public void doSomething(){} >} > > Try this: interp.exec("from MyPackage import MyClass"); /* or just "import MyClass" */ interp.exec("MyObject = MyClass()"); interp.exec("MyObject.doSomething()"); The first line is obviously dependent on your package and class path. Good luck, Ype -- |