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

Thomas Heller thomas.heller at
Fri Jan 25 13:25:21 CET 2002

"Michael Hudson" <mwh at> wrote in message news:u665qhehc.fsf at
> "Thomas Heller" <thomas.heller at> writes:
> > Is it possible to import a module 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.

Bingo! Alex was close, but you seem to have read my mind.

Thanks to you both,


More information about the Python-list mailing list