I want to merge two paths using os.path.join() function. Paths I want to merge are- '/Users/Tushar/Desktop/' and '/Exp'.
I was doing - os.path.join('/Users/Tushar/Desktop','/Exp') and
Expected output was -
'/Users/Tushar/Desktop/Exp'But I actually got -
'/Exp'
Why am I getting this output?
This kind of output is occurring on all systems, macOS, Windows, Linux
I have tried-
os.path.join('/Users/Tushar/Desktop','Exp')and I got the correct output i.e'/Users/Tushar/Desktop/Exp'os.path.join('/Users/Tushar/Desktop/','Exp')and I got the correct output again i.e'/Users/Tushar/Desktop/Exp'os.path.join('/Users/Tushar/Desktop','/Exp','/123')gives'/123'but I expected'/Users/Tushar/Desktop/Exp/123'Apparently
os.path.join('/Users/Tushar/Desktop/,'\\Exp')gives the correct output i.e.'/Users/Tushar/Desktop/\\Exp'where asos.path.join('/Users/Tushar/Desktop/','/Exp')gives the incorrect output'/Exp'.
So far, I have got to the point that it has something to do with the slash (/) at the end of '/Exp' which is the cause of this incorrect output.