简体   繁体   中英

Import Packages from different local folder without sys.path

I have a directory structure like:

proj/
 |- src/
   |- org/
     |- example/
       |- dir/
         |- foo.py
         |- ...
 |- src2/
   |- org/
     |- example/
       |- dir/
         |- bar.py
         |- ...

My question is: How to import foo into bar without using sys.path and, if possible, avoid writing a __init__.py file in every subdirectory of src ? Note that the actual .py files are located in the dir folders only if it's relevant.

from src.org.example.dir import foo

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM