How to run script from interpreter?

Fredrik Lundh fredrik at effbot.org
Fri Jan 19 13:31:54 EST 2001


JustinHJ wrote:
> A cool thing I found out solving my own problem is that a module can be a
> variable. So you want to run a module called 'bobsmodule'
>
>     str = 'bobsmodule'
>     fp, pathname, description = imp.find_module( modname )
>     print 'importing module', modname
>     LoadedModule = imp.load_module( modname, fp, pathname, description)
>     LoadedModule.Afunctioninbobsmodule(i)

or better:

    LoadedModule = __import__('bobsmodule')

Cheers /F





More information about the Python-list mailing list