From: Jack A. <ef...@bi...> - 2001-01-19 03:14:33
|
Hi, I remember a mail to a jpython list last year asking if you could call python modules from jpython. For the case where the python module was written in python, then you need to port from python to jython. But if the python module is an "extension module" -- ie. is written in C (or has a C interface), then it's pretty hard. I'm between jobs at the moment and to keep my brain busy, I've prototyped 'cyphon', a jython module that allows you to call *native* python modules. To give you a use case: Jython 2.0alpha2 on java1.2 (JIT: NONE) Type "copyright", "credits" or "license" for more information. >>> import cyphon >>> string = cyphon.string >>> print string.find('abcde','d') 3 or more usefully: Jython 2.0alpha2 on java1.2 (JIT: NONE) Type "copyright", "credits" or "license" for more information. >>> import cyphon >>> cyphon.os.getenv('PATH') 'DEBUG;C:\\JYTHON' cyphon achieves this by using JNI to embed python in jython: import cyphon # dynamically loads python.dll string = cyphon.string # calls PyImport_ImportModule("string") Now, cyphon would be really useful for using python extension modules like MetaKit or wxPython (to name a couple of extensions that I have an interest in). The complications I forsee are: - inheriting from native python classes - passing callback jython functions to native python functions but I'm sure that these can be resolved. Anyway, having proved to myself that I can get this far, I've lost motivation to complete it. If there's a demand for cyphon, I may polish it up a bit or if anyone can tell me the most convenient way to publish it, let me know. (it's only a few source files) Jack. |