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:
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
-->




More information about the Python-list mailing list