Python中无法导入上一级目录下的包

parentdir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
sys.path.insert(0,parentdir)

比如你要导入的是当前Py文件上一级目录中的某个代码,则parentdir的获取就是使用dirname两次,然后将路径添加到系统中去

Python中无法导入上一级目录下的包最先出现在Python成神之路

版权声明:
作者:lichengxin
链接:https://www.techfm.club/p/25500.html
来源:TechFM
文章版权归作者所有,未经允许请勿转载。

THE END
分享
二维码
< <上一篇
下一篇>>