How can I import a py script by its absolute path name?
could ildg
could.net at gmail.com
Thu Jul 14 22:43:35 EDT 2005
for f in os.listdir(os.path.abspath(libdir)):
module_name = f.strip('.py')
__import__(module_name, globals(), locals(), [])
On 7/14/05, Jesse Noller <jnoller at gmail.com> wrote:
> 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