Jython: Import Modules From Other Sources (DB for instance)?
Question: I'm using a Java program to load and run Jython scripts - using the
org.python.util.PythonInterpreter.

I'm storing the Jython scripts in a database : currently I'm having to extract
the Python scripts to a file system prior to running them - to ensure that any
'import' statements within the scripts work.

Is there a way of avoiding this extraction step: that is - is there a way to
hook into the Python interpreter to intercept the imports and call out to a
Java Method (which would load the jython source from the DB) ?


Answer: You can add importers from either Python or Java (there's a standard one in
the Jython code which imports from the classpath:
`org.python.core.ClasspathPyImporter`; there's also some Javadocs in the
`org.python.core.util.importer` interface it implements which may be useful).
The code is relatively simple; see [PEP
302](http://www.python.org/dev/peps/pep-0302/) as well.

