Importing User-defined Modules

W

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?
 
T

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
 
A

and-google

Walter Brunswick said:
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.
 
W

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top