From: Carlos Q. <car...@we...> - 2001-09-26 21:11:46
|
On Wednesday 26 September 2001 23:57, Mat...@i2... wrote: Some answers > Hi all, > > I recently discovered jython - I must say, very cool! > > I'm trying to embed a jython interpreter within a java application, and I > have most things working, but have a few questions: > > 1) With an embedded interpreter, do I still need the jython distribution > directory in order for the scripts I run to have access to the standard > lib (Lib\*.py)? Yes, or you can create a jar containin al libs and distribute that. In this case you have to explictly add the file to sys.path > 2) How do I add an instance of a Java object to the namespace I pass to > the PythonInterpreter exec() method? You can set a variable beforfe interpeter.set(object, "name") interpeter.exec("foo(name)") > 3) How do I programmatically define a python class (and instantiate it) > and pass it to the interpreter as in (2) ? By programmatically I mean > calling a bunch of java methods and _not_ simply evaluating a string that > has my python class. Can you explain this a little bit better, do you want to programatically define the class interface and implementation? > 4) W.r.t (2) and (3) what I'm really trying to do is delegate to a Java > instance from a Python instance so I can default some of the arguments on > some methods (i.e. make a nicer interface to my java internals for the > script writers). Any tips on how to do this? > 5) I setup my own SecurityManager to deny exits so that scripts can't > terminate my java process - anyone know of a better way to do this? Not me at least > 6) If no to (5), I wrap my script execution in a try/except block to catch > my DenyExitSecurityException, thus enabling me to swallow the ugly stack > trace when a script calls exit, however, this only works when the script > calls the java System.exit(), with sys.exit() I still get the stack trace. > Any idea how to stop this before I go digging around in the code? > > Any help appreciated, thanks, > > Matt > mat...@i2... > > > _______________________________________________ > Jython-users mailing list > Jyt...@li... > https://lists.sourceforge.net/lists/listinfo/jython-users |