From: <bc...@wo...> - 2001-06-08 17:18:22
|
[Mike Barton] >Jython code, compiled with jythonc into Java is accessible from >Java but not from another Jython script. [finn] >Correct. Workarounds are available, but they are ugly. [Mike Barton] >Where are the workarounds done? In the jython script. If "foo.py" is a module that have been compiled with jythonc: import java class foo(java.lang.Object): def toString(self): return "foo.toString" def bar(self, arg): """@sig int bar(int arg)""" return arg + 1 then this jythonc compiled module can be used from a jython script by importing it like this: #import foo import foo as fooClass import new foo = new.module("foo") fooClass.moduleDictInit(foo.__dict__) f = foo.foo() print f.toString() print f.bar(43) The thing to notice is that a bare "import foo" will not import foo as a module but it will import the java class. The 4 lines at the beginning will wrap this java class in a module called "foo". If you use this, keep in mind that it is a hack. You may be forced to remove the hack when you upgrade to a later version of jython. regards, finn |