Load Arbitrary Script as Module?

rgb122 at my-deja.com rgb122 at my-deja.com
Wed May 10 10:50:47 EDT 2000


The line:

exec source in vars(module)

was giving me trouble since it tried to evaluate the filename as a
python statement. I replaced it with:

execfile(source, vars(module))

which seems to be working fine (for the few test I've done so far).

Thanks,
Rob


In article <3X8S4.3482$wYl.200101376 at newsb.telia.net>,
  "Fredrik Lundh" <effbot at telia.com> wrote:
> rgb122 at my-deja.com wrote:
> > Is there a way to load a module given a full filepath? Something
like:
> >
> > driver = LoadModule("C:\\Stuff\\sample.py")
> > driver.someFunction()
>
> start here:
> http://www.deja.com/=dnc/getdoc.xp?AN=621152936
>
> and add something like:
>
> def import_file(filename):
>     name = os.path.splitext(os.path.basename(filename))[0]
>     return do_import(name, filename)
>
> driver = import_file("c:/Stuff/sample.py")
> driver.someFunction()
>
> hope this helps!
>
> </F>
>
> <!-- (the eff-bot guide to) the standard python library:
> http://www.pythonware.com/people/fredrik/librarybook.htm
> -->
>
>


Sent via Deja.com http://www.deja.com/
Before you buy.



More information about the Python-list mailing list