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

harold fellermann harold.fellermann at
Thu Jul 14 16:58:34 CEST 2005

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

have a look at help(__import__) to import a module whose name is given 
as a string.

- harold -

Tages Arbeit, abends Gäste,
saure Wochen, frohe Feste!
-- Johann Wolfgang v. Goethe

More information about the Python-list mailing list