Importing User-defined Modules

Thomas Guettler guettli at
Mon Jul 25 11:13:55 CEST 2005

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 (, 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__

Copy the bytecode somewhere.


Thomas Güttler,

More information about the Python-list mailing list