我猜这个问题可能已经得到解答,但我所有的搜索都发现了其他导入问题。话又说回来,也许我只是不知道要搜索的正确术语。
如果我创建一个带有模块的包,似乎我可以使用from mypackage import mymodule
to use mymodule
在我的代码中。但是,我不能使用import mypackage
然后使用mypackage.mymodule
。有了这个我得到了AttributeError: 'module' object has no attribute 'mymodule'
错误。为什么会这样?我该如何设置才能使用它?
我的包结构如下所示。一切__init__.py
s 为空。
myproject
__init__.py
mypackage
__init__.py
mymodule.py
mymain.py # Doing the importing.
子模块不会隐式导入。您将需要导入.mymodule
in mypackage/__init__.py
除非你明确想要导入mypackage.mymodule
.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)