Python导包

https://blog.csdn.net/summer_my_sunshine/article/details/128062975

网上查阅了资料,大体了解了本地导包的基本原理

如果我的本地目录结构是这样的

└── hideapi

​ ├── common

​ ├── color.py

​ ├── __ init__.py

​ └── utils.py

​ └── memory

​ └── analysis_memory

​ ├── __ init__.py

​ ├── memory_comparison_for_memory_peaking.py

​ └── memory_file_parse_for_memory_peaking.py

示例如下

# 将 项目的根目录添加到sys.path中
BASE_DIR = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
if not sys.path.__contains__(BASE_DIR):
    sys.path.append(BASE_DIR)
    print("add {} to sys.path".format(BASE_DIR))
 
from common.utils import *
from utils import *

参考

https://www.jianshu.com/p/59bfaf0499e1

https://python3-cookbook.readthedocs.io/zh_CN/latest/c10/p03_import_submodules_by_relative_names.html