我曾尝试阅读有关兄弟导入的问题,甚至包括包文档,但我仍然没有找到答案。
使用以下结构:
├── LICENSE.md
├── README.md
├── api
│ ├── __init__.py
│ ├── api.py
│ └── api_key.py
├── examples
│ ├── __init__.py
│ ├── example_one.py
│ └── example_two.py
└── tests
│ ├── __init__.py
│ └── test_one.py
如何让 examples
和 tests
目录下的脚本能够从 api
模块导入并且能够从命令行运行?
另外,我想避免为每个文件使用丑陋的 sys.path.insert
hack。这在 Python 中肯定有更好的方法,对吗?
sys.path
黑科技,阅读到目前为止唯一实际的解决方案(在7年之后!)链接。 - Aran-Fey