From: Wouter D. <wou...@te...> - 2007-11-15 12:13:56
|
Hi, why can't I access an Java Object during the import of a module. In Java, I have: DrawMediator drawMediator = new DrawMediator(); PythonInterpreter interp = new PythonInterpreter(); interp.set("DrawMediator", drawMediator); I have a module called header.py which has to be imported, but I can't reference the DrawMediator object during that import process. I get: "NameError: DrawMediator" I CAN however reference the DrawMediator object once header.py (or any other module for that matter) is processed (in that case offcourse I have to adapt header.py first so it gets imported without errors) The same is true for a simple String that I want to reference during the module load phase. What am I doing wrong ? Kind regards, Wouter |
From: Jeff E. <jem...@fr...> - 2007-11-16 16:03:32
|
Modules don't inherit the namespace of those that import them. If you name the interpreter locals namespace, say '__main__', then your module could do this from __main__ import DrawMediator To name the namespace, create your interpreter like this: _interp = new PythonInterpreter(); PyModule mod = imp.addModule("__main__"); _interp.setLocals(mod.__dict__); _interp.set("DrawMediator", drawMediator); _interp.exec("import header"); Wouter Deketelaere wrote: > Hi, > > why can't I access an Java Object during the import of a module. > > In Java, I have: > > DrawMediator drawMediator = new DrawMediator(); > PythonInterpreter interp = new PythonInterpreter(); > interp.set("DrawMediator", drawMediator); > > I have a module called header.py which has to be imported, but I can't > reference the DrawMediator object during that import process. I get: > "NameError: DrawMediator" > > I CAN however reference the DrawMediator object once header.py (or any > other module for that matter) is processed (in that case offcourse I > have to adapt header.py first so it gets imported without errors) > > The same is true for a simple String that I want to reference during the > module load phase. > > What am I doing wrong ? > Kind regards, > Wouter > > > > ------------------------------------------------------------------------- > This SF.net email is sponsored by: Splunk Inc. > Still grepping through log files to find problems? Stop. > Now Search log events and configuration files using AJAX and a browser. > Download your FREE copy of Splunk now >> http://get.splunk.com/ > _______________________________________________ > Jython-users mailing list > Jyt...@li... > https://lists.sourceforge.net/lists/listinfo/jython-users |