这是我的目录的样子:
my_library
├── my_module
│ ├── __init__.py
│ ├── core.py
│ ├── helpers.py
│ └── interface.py
├── __init__.py
├── setup.py
└── README.md
core.py
包含主类Generator
,interface.py
包含一堆用户希望与该类一起使用的变量和函数(用于设置参数等),最后是{ {1}}包含helpers.py
使用的一堆用户不感兴趣的功能。
我正在尝试使用core.py
中helper.py
中定义的辅助函数(依次使用interface.py
中的参数)。我的问题是在三个模块文件和core.py
中进行导入的最佳方式是什么?我的目标是,当用户执行__init__.py
时,他们将能够访问my_module.
类和Generator
文件中的所有内容,但不能访问interface.py
中的内容(至少不能直接访问) ,他们将不得不再下一层)。
我的helpers.py
的{{1}}当前看起来像这样:
my_module
__init__.py
和from .core import Generator
from .interface import *
from .base_functions import *
都具有core.py
的{{1}},以使用helper.py
和import my_module
中的定义其他人。
我目前所从事的工作在一定程度上是可行的,但是我不确定它是否是最佳选择,尤其是我读到使用星号(helper.py
)导入并不是一个好主意。