Jam*_*ton 10
您不能依赖已加载模块的内省,因为可能尚未加载子包.假设有问题的顶级包不是egg,zip文件,扩展模块或从内存加载,你必须查看文件系统.
def get_subpackages(module):
dir = os.path.dirname(module.__file__)
def is_package(d):
d = os.path.join(dir, d)
return os.path.isdir(d) and glob.glob(os.path.join(d, '__init__.py*'))
return filter(is_package, os.listdir(dir))
Run Code Online (Sandbox Code Playgroud)