From: Guy Gascoigne-P. <gg...@tr...> - 2002-02-06 11:13:20
|
Wow, that opens up a whole avenue of ways to integrate jython and java that I'd never realized. Thanks for the example; it makes things a whole lot clearer. Guy - who still can't believe just how cool jython is :-) -----Original Message----- From: bc...@wo... [mailto:bc...@wo...] Sent: Wednesday, February 06, 2002 2:52 AM To: 'jyt...@li...' Cc: Guy Gascoigne-Piggford Subject: Re: [Jython-users] Accessing Jython Regular Expressions from java [Guy Gascoigne-Piggford] >I guess that I didn't explain my self very clearly, though I think that you >did answer my question. I've written a java module that extends jython, I >want that java module to use regular expressions in the same way that jython >does. As you say No, that is not quite what I said. I meant that sre only works in a jython environment. >that would involve using sre and I can't do that from a >java module :-( A java class like this below can imported from jython and can make use of all the other jython modules, classes and functions. import org.python.core.*; public class y { public static void test() { // import re PyObject re = __builtin__.__import__("re"); // res = re.match(r"(source filename|Name of).*\?(?i)", "nAME OF ?") PyObject res = re.invoke("match", Py.java2py("(source filename|Name of).*\\?(?i)"), Py.java2py("nAME OF ?")); // print res.group(1) System.out.println(res.invoke("group", Py.newInteger(1))); } } Jython 2.1+ on java1.4.0-beta3 (JIT: null) Type "copyright", "credits" or "license" for more information. >>> import y >>> y.test() nAME OF regards, finn |