Python 在子包中动态导入模块

Python 在子包中动态导入模块,python,python-import,Python,Python Import,我试图导入uberModule并检索类测试,但getattr找不到,为什么?谢谢 AttributeError: 'module' object has no attribute 'test' 这是我的代码main.py: from importlib import import_module module = import_module("modules.uberModule") cls = getattr(module, 'test') uberModule.py: class test

我试图导入uberModule并检索类测试,但getattr找不到,为什么?谢谢

AttributeError: 'module' object has no attribute 'test'
这是我的代码main.py:

from importlib import import_module
module = import_module("modules.uberModule")
cls = getattr(module, 'test')
uberModule.py:

class test():
    def __init__(self):
       print "such wow"
目录结构:

.
├── modules
│   ├── __init__.py
│   └── uberModule
│       ├── __init__.py
│       └── uberModule.py
├── __init__.py
├── main.py
这应该是:

module = import_module("modules.uberModule.uberModule")
除非uberModule/\uuuuu init\uuuuuu.py导入uberModule的内容,否则我猜不会

您也必须编写模块,不是吗?仔细想想,这是合乎逻辑的:如果不想写两次,可以在uberModule/\uuuuu init\uuuuuuu.py内执行类似于.uberModule import*的操作