Imp.get_suffixes ()
Returns a 3-tuple list (suffix, mode, type) for a description of the special module. suffix is the file suffix; mode is the open file model; The type is file types, 1 for Py_source, 2 for py_compiled, and 3 for c_extension
>>> imp.get_suffixes()[(‘.x86_64-linux-gnu.so‘‘rb‘3), (‘.so‘‘rb‘3), (‘module.so‘‘rb‘3), (‘.py‘‘U‘1), (‘.pyc‘‘rb‘2)]
Imp.find_module (name[, Path])
- If path is empty, the module name is searched according to the Sys.path path, and the ternary group (file, pathname, description) is returned. File is a newly opened module, pathname is the path of the module, description is imp.get_ Suffixes () returns the tuple.
- If the module is a package, file returns None, Pathname is the package path, and the type returned by description is pkg_directory.
- Find_module does not process the module name of the hierarchy (with '. ') Module name module.name1.name2).
- "Path" must be a list.
>>> print imp.find_module(‘os‘)(<openfile‘/usr/lib/python2.7/os.py‘‘U‘at0x7fdeebd53a50‘/usr/lib/python2.7/os.py‘, (‘.py‘‘U‘1))
Imp.load_module (name, file, pathname, description)
- Load a module that was found by Find_module. If the module has already been loaded, it is equivalent to reload ().
- When a module is a package or is not loaded from a file, file and pathname can be none and ".
- Returns a Module object after a successful load, or throws a Importerror exception.
- Need to close file yourself, preferably with try...finally ...
Instance
>>> file, pathname, desc = imp.find_module(‘os‘)>>> myos = imp.load_module(‘sep‘, file, pathname, desc)>>> ‘sep‘from‘/usr/lib/python2.7/os.pyc‘>>>> myos.getcwd()‘/home/ydoing/github/autorunner‘
The Imp module for Python