Manipulating Directory Paths in Python
Posted
by G Ullman
on Stack Overflow
See other posts from Stack Overflow
or by G Ullman
Published on 2010-06-09T18:32:59Z
Indexed on
2010/06/09
18:52 UTC
Read the original article
Hit count: 171
Basically I've got this current url and this other key that I want to merge into a new url, but there are three different cases.
Suppose the current url is localhost:32401/A/B/foo
if key is bar then I want to return localhost:32401/A/B/bar
if key starts with a slash and is /A/bar then I want to return localhost:32401/A/bar
finally if key is its own independent url then I just want to return that key = htt p://foo.com/bar -> http://foo.com/bar
I assume there is a way to do at least the first two cases without manipulating the strings manually, but nothing jumped out at me immediately in the os.path module.
© Stack Overflow or respective owner