我有一个嵌套类,类似于
/Foo
__init__.py
pitythefoo.py
kungfoo.py
/Bar
__init__.py
spam.py
eggs.py
我的__init__.py
文件当前有
__all__ = ['pitythefoo', 'kungfoo']
对于/Foo/__init__.py
文件
__all__ = ['spam', 'eggs']
对于/Foo/Bar/__init__.py
文件
所以我可以使用
from Foo.Bar import *
spam
eggs
不过,我想访问垃圾邮件和鸡蛋使用
from Foo import Bar
Bar.spam
Bar.eggs
在我的__init__.py
文件中是否有一些代码可以用来进行这种导入
您可以通过修改
Foo/Bar/__init__.py
来绕过它:它很管用,但绝对不优雅
编辑:
正如Andrea Corbellini在上面的评论中指出的,您可以避免星型导入:
相关问题 更多 >
编程相关推荐