mixed slashes with os.path.join on windows

前端 未结 7 1447
一生所求
一生所求 2020-11-27 04:39

I tend to use only forward slashes for paths (\'/\') and python is happy with it also on windows. In the description of os.path.join it says that is the correct way if you w

7条回答
  •  长情又很酷
    2020-11-27 05:01

    try using abspath (using python 3)

    import os
    
    a = 'c:/'
    b = 'myFirstDirectory/'
    c = 'mySecondDirectory'
    d = 'myThirdDirectory'
    e = 'myExecutable.exe'
    
    
    print(os.path.abspath(os.path.join(a, b, c, d, e)))
    

    OUTPUT:

    c:\myFirstDirectory\mySecondDirectory\myThirdDirectory\myExecutable.exe

    Process finished with exit code 0

提交回复
热议问题