Python 3.x 在某些情况下,os.path.join提供不正确的输出
我想使用os.path.join()函数合并两个路径。我要合并的路径是-Python 3.x 在某些情况下,os.path.join提供不正确的输出,python-3.x,python-2.7,os.path,Python 3.x,Python 2.7,Os.path,我想使用os.path.join()函数合并两个路径。我要合并的路径是-'/Users/Tushar/Desktop/'和'/Exp' 我在做-os.path.join('/Users/Tushar/Desktop','/Exp')和 预期输出为-'/Users/Tushar/Desktop/Exp' 但实际上我得到了-'/Exp' 为什么我得到这个输出 这种输出出现在所有系统上,包括macOS、Windows和Linux 我试过了- os.path.join('/Users/Tushar/
'/Users/Tushar/Desktop/'
和'/Exp'
我在做-os.path.join('/Users/Tushar/Desktop','/Exp')
和
- 预期输出为-
'/Users/Tushar/Desktop/Exp'
- 但实际上我得到了-
'/Exp'
os.path.join('/Users/Tushar/Desktop','Exp')
我得到了正确的输出,即'/Users/Tushar/Desktop/Exp'
os.path.join('/Users/Tushar/Desktop/','Exp')
我再次得到了正确的输出,即'/Users/Tushar/Desktop/Exp'
os.path.join('/Users/Tushar/Desktop','/Exp','/123')
给出了'/123'
,但我期望的是'/Users/Tushar/Desktop/Exp/123'
os.path.join('/Users/Tushar/Desktop/,'\\Exp')
给出了正确的输出,即'/Users/Tushar/Desktop/\\Exp'
其中asos.path.join('/Users/Tushar/Desktop/,'/Exp')
给出了错误的输出'/Exp'
def my_join(根,*args):
args=[args中arg的arg.lstrip(os.path.sep)]
返回os.path.join(根,*args)
见示例:
>>我的加入('/home/ibug'、'/oh'、'/yeah'、'/hasty')
“/家/ibug/哦/是的/很帅”