Python's imp.find_module
imp.find_module(name [, path])
Parameters
name
The name of the module (directory or file without extension).Path
-
If ommitted checks builtins first, then the sys.path directories
-
If given:
- must be a list of directory names
- Searches directories for the module
Return
A 3-tuple of (file, pathname, description).File
An opened file or None if the module is a package (directory);Pathname
The path to the file or directory.Description
A 3-tuple of (suffix, mode, type):
- suffix is the file extension (e.g. .py)
- mode is one of r or rb (file was opened as readable text or binary)
- type is one of PY_SOURCE, PY_COMPILED, C_EXTENSION, or PKG_DIRECTORY
Raise
ImportError if the module isn't found.Subdirectories
The method doesn't accept dotted notation to indicate that the module is in a sub-package. Instead you have to find the package first then the module:path = os.path.dirname(__file__)
f, p, d = find_module('directory', [path])
f_2, p_2, d_2 = find_module('module_name', [p]))