, os.path.join , :
import os
p1 = os.path.join(os.sep, 'foo1', 'foo2')
p2 = os.path.join(os.sep, 'foo', 'bar.txt')
os.path.join(p1, p2.lstrip(os.sep))
If you want to change the paths, you can also do cool things like using lists:
os.path.join(p1, *[x.lower() for x in p2.split(os.sep)])
source
share