I tried to use
Here is how to do it
>>> import urlparse >>> urlparse.urljoin("ftp://domain.com/a/b/c/d/", "../..") 'ftp://domain.com/a/b/' >>> urlparse.urljoin("ftp://domain.com/a/b/c/d/e.txt", "../..") 'ftp://domain.com/a/b/'
urljoin consider a path/directory all until the last
/ - after this is the filename, if any.
Also, do not add a leading
/ to the second parameter, otherwise you will not get the expected result.
os.path module is platform dependent but for file paths using only slashes but not-URLs you could use