稍微摆弄一下之后,我意识到了如何设置它,并且出于特定性考虑,我将不使用foo bar名称。我的项目目录设置为…
tools/
core/
object_editor/
# files that need to use ntlib.py
editor.py # see example at bottom
__init__.py
state_editor/
# files that need to use ntlib.py
__init__.py
ntlib.py
__init__.py # core is the top level package
LICENSE
state_editor.py # equivalent to main.py for the state editor
object_editor.py # equivalent to main.py for the object editor
一条线object_editor.py
看起来像…
from core.object_editor import editor
一条线editor.py
看起来像…
from .. import ntlib
或者
from core import ntlib
关键是在我给问题的示例中,“主要”脚本是从程序包中运行的。一旦将其移出,创建了一个特定的程序包(core
),然后将我希望编辑者共享的库(ntlib
)移到该程序包中,一切就变得很笨拙了。