我倾向于只对路径('/')使用正斜杠,python 对它在 Windows 上也很满意。在 os.path.join 的描述中,如果你想跨平台,这是正确的方法。但是当我使用它时,我得到了混合斜线:
import os
a = 'c:/'
b = 'myFirstDirectory/'
c = 'mySecondDirectory'
d = 'myThirdDirectory'
e = 'myExecutable.exe'
print os.path.join(a, b, c, d, e)
# Result:
c:/myFirstDirectory/mySecondDirectory\myThirdDirectory\myExecutable.exe
这个对吗?我应该事后检查并纠正它还是有更好的方法?
谢谢
编辑:询问路径时,我也会得到混合斜线
import sys
for item in sys.path:
print item
# Result:
C:\Program Files\Autodesk\Maya2013.5\bin
C:\Program Files\Autodesk\Maya2013.5\mentalray\scripts\AETemplates
C:\Program Files\Autodesk\Maya2013.5\Python
C:\Program Files\Autodesk\Maya2013.5\Python\lib\site-packages
C:\Program Files\Autodesk\Maya2013.5\bin\python26.zip\lib-tk
C:/Users/nookie/Documents/maya/2013.5-x64/prefs/scripts
C:/Users/nookie/Documents/maya/2013.5-x64/scripts
C:/Users/nookie/Documents/maya/scripts
C:\Program Files\Nuke7.0v4\lib\site-packages
C:\Program Files\Nuke7.0v4/plugins/modules