Re: Importing User-defined Modules

2005-07-25 Thread Thomas Guettler
Am Sun, 24 Jul 2005 13:12:04 -0400 schrieb Walter Brunswick:

 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?

You could do it like this:

Copy the file to directory which is in sys.path. Give the file
the extension .py. Import it with __import__
(http://docs.python.org/lib/built-in-funcs.html#l2h-6)

Copy the bytecode somewhere.

HTH,
  Thomas

-- 
Thomas Güttler, http://www.thomas-guettler.de/


-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Importing User-defined Modules

2005-07-25 Thread and-google
Walter Brunswick [EMAIL PROTECTED] 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.

You shouldn't really need a PEP for that; you can take control of the
compile and import processes manually. See the py_compile and imp
modules.

-- 
Andrew Clover
mailto:[EMAIL PROTECTED]
http://www.doxdesk.com/

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Importing User-defined Modules

2005-07-25 Thread Walter Brunswick
Thomas Guettler, your solution was very impractical besides being ignorant of 
my problem. Thanks for trying nonetheless.

Andrew Clover, that is exactly what I was looking for. A few examples would 
have been nice, but I think I can manage from here. 
Thanks you. 


-- 
http://mail.python.org/mailman/listinfo/python-list


Importing User-defined Modules

2005-07-24 Thread Walter Brunswick
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? 


-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Importing User-defined Modules

2005-07-24 Thread Steve Holden

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