How can I import a py script by its absolute path name?

Jesse Noller jnoller at
Thu Jul 14 16:42:38 CEST 2005

A question in a similiar vein:

I have appended 2 different directories to my path (via
sys.path.append) now - without knowing the names of the files in those
directories, I want to force an import of the libraries ala:

for f in os.listdir(os.path.abspath(libdir)):
    module_name = f.strip('.py')
    import module_name

Obviously, this throws:

ImportError: No module named module_name

Is there some way to do this?


More information about the Python-list mailing list