返回3元组列表(suffix, mode, type), 获得特殊模块的描述.suffix为文件后缀名;mode为打开文件模式; type为文件类型, 1代表PY_SOURCE, 2代表PY_COMPILED, 3代表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)]
>>> print imp.find_module(‘os‘)
(<open file ‘/usr/lib/python2.7/os.py‘, mode ‘U‘ at 0x7fdeebd53a50>, ‘/usr/lib/python2.7/os.py‘, (‘.py‘, ‘U‘, 1))
实例
>>> file, pathname, desc = imp.find_module(‘os‘)
>>> myos = imp.load_module(‘sep‘, file, pathname, desc)
>>> myos
<module ‘sep‘ from ‘/usr/lib/python2.7/os.pyc‘>
>>> myos.getcwd()
‘/home/ydoing/github/autorunner‘
原文地址:http://blog.csdn.net/csujiangyu/article/details/45285897