从子模块隐式导入 [英] Implicit import from submodules
本文介绍了从子模块隐式导入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个像这样的包裹:
I've got a package like this:
foo/
__init__.py
bar.py
baz.py
我想在导入foo
时自动使用子模块的功能.因此,如果bar.py
在某处具有def spam()
,我希望能够像foo.spam()
一样直接调用它.最好的方法是什么?
I'd like to have submodules' functions automatically available when I import foo
. So if bar.py
has def spam()
somewhere, I'd like to be able to call it directly like foo.spam()
. What would be the best way to achieve that?
推荐答案
在__init__.py
内部,执行from bar import spam
.
这篇关于从子模块隐式导入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文