On 11/08/2011 10:48 PM, Pierre Thibault wrote:
2011/11/8 Philipp Zech <zech.ph@gmail.com>
so now, if trying to get an instance of a python class via the object
factory, as done according to the above mentioned book, i get the error
that one of my modules, namely building (building.py) is not found,
however the package itself (base) is found. I kinda assume this is due
to the java interface implemented by the python class and that it's not
found, however, up to now, i couldn't figure a way out on how to resolve
this issue. Maybe someone can give me a hint on what I'm doing wrong.
Any help will be appreciated!
Thanks in advance!



As I see, are you importing "building"? I think you need to import "from base import building". building is inside the package base.


Pierre Thibault

Python Developer/Développeur Python
Montréal, QC

RSA(R) Conference 2012
Save $700 by Nov 18
Register now

Jython-users mailing list
Hi Pierre,

thanks for your answer, however, there should be anything wrong with my importing statements (see below):

        public JythonObjectFactory (Class<?> interfaceType, String moduleName, String className)
            this.interfaceType = interfaceType;
            final PyObject importer = state.builtins.__getitem__(Py.newString("__import__"));
            final PyObject module = importer.__call__(Py.newString(moduleName));
            clazz = module.__getattr__(className);sepp

so the above method is ued to get the module and based on it get an instancen of the pythonclass Building (defined inside building .py). In the main method of this small program i create a buildiongFactory and try to get an isntance of building via the following code:

        JythonObjectFactory buildingFactory = new JythonObjectFactory(BuildingType.class, "base.building", "Building");
        BuildingType building = (BuildingType) buildingFactory.createObject();

as can be seen from those two code excerpts, i actually try to import the module "building" from the package "base", however, no success so far. Interestingly, if I start to mess around with the package name, i.e.: replacing it by "foo", the python interpreter claims that this very module named "foo" cannot be found, which is true, as it is non-existent (see below):

        JythonObjectFactory buildingFactory = new JythonObjectFactory(BuildingType.class, "foo.building", "Building");

leads to

        Exception in thread "main" Traceback (innermost last):
          (no code object) at line 0
        ImportError: no module named foo

yet, changing the package name back to "base" leads to the previous error:

        Exception in thread "main" Traceback (innermost last):
          (no code object) at line 0
        ImportError: No module named building

This kinda looks like the package can be found, yet the module cannot be created, yet I have no clue why this happens...again, maybe someone out there can give me the needed hint!

thanks again in advance!