多个路径下python库导入

前言

有时候写代码, 会从一个文件夹中的py文件import 所在文件夹的父文件夹下某个文件的模块。



sys

|--a
    |--a_a.py
|--utils.py

假设我们在写a_a.py, 需要引入utils.py中的 tools类,则可以这么写

# 其他import ...
import sys
sys.path.append('..')
from utils import tools

虽然很straightforward, 但是显得比较不优雅。



importlib

todo…


Isort

Isort 自动整理 import 的超实用工具教程

todo…

猜你喜欢

转载自blog.csdn.net/weixin_43850253/article/details/126310525