Import and absolute file names, sys.path including ''... or not

greg greg at cosc.canterbury.ac.nz
Thu May 21 04:33:51 EDT 2009


Jean-Michel Pichavant wrote:

> __import__('/home/jeanmichel/test')

The __import__ function takes *module* names, not
filesystem pathnames.

Giving it a pathname might happen to work some of
the time in some versions of Python, but it's not
an intended feature, and you shouldn't rely on it.

If you want to execute the contents of an arbitrary
file, rather than a module existing somewhere in the
Python module namespace, use execfile().

-- 
Greg



More information about the Python-list mailing list