python windows os.path.join 错误 路径 到达驱动器
import os
import sys
BASE = os.path.join(os.path.dirname('D:/Data/Documents/Blog/pyblog/scripts/python/renderer/__configs.py'), '../../../')
print(BASE)
python_dir = os.path.join(BASE, '/scripts/python')
print(python_dir)
D:/Data/Documents/Blog/pyblog/scripts/python/renderer\../../../
D:/scripts/python
注意!上级目录不要加 /XXX
,应该直接是XXX
或者./XXX
Linux同理
python_dir = os.path.join(BASE, './scripts/python')
D:/Data/Documents/Blog/pyblog/scripts/python/renderer../../../
D:/Data/Documents/Blog/pyblog/scripts/python/renderer../../.././scripts/python
如何实现跨平台的绝对路径处理
python_dir = os.path.normpath(python_dir)
本博文本意在于记录个人的思考与经验,部分博文采用英语写作,可能影响可读性,请见谅
本文来自博客园,作者:ZXYFrank,转载请注明原文链接:https://www.cnblogs.com/zxyfrank/p/16555864.html