Importing a module without creating a .pyc/.pyo file?

Michael Hudson mwh at python.net
Fri Jan 25 06:09:46 EST 2002


"Thomas Heller" <thomas.heller at ion-tof.com> writes:

> Is it possible to import a module xxx.py without compiling it
> (implicitely) to .pyo/.pyc, or do I always have to delete the
> compiled file afterwards if it gets in the way?

Like Alex said, you could use imp, or you could just do it by hand

newm = new.module(name)
sys.modules[name] = newm
newm.__file__ = filepath
exec compile(open(filepath).read(), filepath, "exec") in \
        newm.__dict__

comes fairly close, I think.

Cheers,
M.

-- 
  $ head -n 2 src/bash/bash-2.04/unwind_prot.c
   /* I can't stand it anymore!  Please can't we just write the
      whole Unix system in lisp or something? */
                                       -- spotted by Rich van der Hoff



More information about the Python-list mailing list