Walter Brunswick wrote:
I need to import modules with user-defined file extensions that differ from '.py', and also (if possible) redirect the bytecode output of the file to a file of a user-defined extension. I've already read PEP 302 (http://www.python.org/peps/pep-0302.html), but I didn't fully understand it. Would someone [who understands it] please be able to give me a synopsis of it, along with a few explanatory examples, or some other alternatives, if any?Well, under the PEP302 regime, as well as all the usual suspects you can add to sys.path you can also add "importer" objects. These objects will have specific methods (find_module and load_module) called at specific times during the import process.
Because there can be a significant amount of time spent initializing an importer object the system now uses a cache of importers, which it's sensible to clear when adding a new importer.
I attach code below that implements an importer that loads modules from a database, plus the program that actually creates the database containing the modules. This was only a test of my understanding, but it may help you to move further towards PEP302.
regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/
dbload.py
Description: application/python
dbimp.py
Description: application/python
-- http://mail.python.org/mailman/listinfo/python-list