Importing files other than *.py

Ed Leafe ed at leafe.com
Fri Nov 19 15:12:31 EST 2004


On Nov 19, 2004, at 5:10 AM, Denis S. Otkidach wrote:

> Yes, it's possible:
>
> [snip]

> fp = open('burp.zz', 'U')
>>>> import imp
>>>> module = imp.load_module('burp', fp, 'burp.zz', ('.py', 'U', 1))
>>>> module
> <module 'burp' from 'burp.zz'>
>>>> module.f
> <function f at 0x307a04>
>>>> module.f()
> OK

	Cool! I had tried several variations, but couldn't get imp to import 
the module properly. This worked, though. Thanks for your help.

      ___/
     /
    __/
   /
  ____/
  Ed Leafe
  http://leafe.com/
  http://dabodev.com/




More information about the Python-list mailing list