[英]Import Packages from different local folder without sys.path
我有一個類似的目錄結構:
proj/
|- src/
|- org/
|- example/
|- dir/
|- foo.py
|- ...
|- src2/
|- org/
|- example/
|- dir/
|- bar.py
|- ...
我的問題是:如何在不使用sys.path
情況下將foo
導入bar
,並盡可能避免在src
每個子目錄中寫入__init__.py
文件? 請注意,僅當相關.py文件時,它們才位於dir
文件夾中。
from src.org.example.dir import foo
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.