jupyter notebook导入上级目录的文件

在jupyter中,使用:os.path.realpath(".")可以得到当前文件的路径

import sys
import os
os.chdir(os.path.dirname(os.path.realpath(".")))
sys.path.insert(0, '..') # 添加上级路径

后面的代码不用变,后续再导入上级路径的时候就不会报找不到路径/模块了

猜你喜欢

转载自blog.csdn.net/weixin_35757704/article/details/130987169
今日推荐