Load Arbitrary Script as Module?

Fredrik Lundh effbot at telia.com
Wed May 10 04:18:07 EDT 2000

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:

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")

hope this helps!


<!-- (the eff-bot guide to) the standard python library:

More information about the Python-list mailing list