faqts : Computers : Programming : Languages : Python : Modules

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

7 of 7 people (100%) answered Yes
Recently 4 of 4 people (100%) answered Yes

Entry

Is there a way to load a module given a full filepath?

May 10th, 2000 02:50
unknown unknown, Fredrik Lundh


Given something like:
 
 driver = LoadModule("C:\\Stuff\\sample.py")
 driver.someFunction()

ANSWER::

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!