Importing files other than *.py

M.E.Farmer mefjr75 at
Fri Nov 19 23:11:33 CET 2004

Ed Leafe wrote in message:
> If I have a Python script in a file named "burp.zz", is there any way 
> to import it into another script as you can with files named with the 
> .py extension?
> 	I looked at the imp module, but was not able to make it do what I 
> wanted. Is this possible, or is the py/pyc extension required?
>   Ed Leafe
Hello Ed,
You can import as usuall if you do this:
Save this to your path.

import imputil

# define your custom file handler
def handle_zz(filepath, fileinfo, filename):
    sourcefile = open(filepath, 'r')
    data =
    return 0, compile(data, filepath, 'exec'),{}

importer = imputil.ImportManager()
importer.add_suffix('.zz', handle_zz)
# end

Now do this in your code:
import zz_import #now you can import zz files
import burp

If module is not found it will raise an ImportError.


More information about the Python-list mailing list