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

Jesse Noller jnoller at gmail.com
Thu Jul 14 10:42:38 EDT 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?

thanks
-jesse



More information about the Python-list mailing list