[Python-ideas] os.path.join

Bruce Leban bruce at leapyear.org
Mon Nov 4 18:45:24 CET 2013


On Mon, Nov 4, 2013 at 7:29 AM, anatoly techtonik <techtonik at gmail.com>wrote:

> Right. But I am working more with URL paths nowadays. In there if I
> want to join two paths, no matter if 2nd starts with slash or not, I
> don't really expect the 2nd to rewrite the first.
>

Joining url paths is different from joining file system paths. I wouldn't
suggest using a function designed for one to do the other.

urljoin('https://s/a/b/', 'x')        => 'https://s/a/b/x')
urljoin('https://s/a/b/', '/x/y')     => 'https://s/x/y')
urljoin('https://s/a/b/', '//t/x/y')  => 'https://t/x/y')
urljoin('https://s/a/b/', '//t')      => 'https://t/a/b')
urljoin('https://s/a/b/', 'http:')    => 'http://s/a/b')
urljoin('http:', '//s', 'x/y')        => 'http://s/x/y')

Note that I'm ignoring the issue of whether or not the last part of the url
on the left should be stripped off.

--- Bruce
I'm hiring: http://www.cadencemd.com/info/jobs
Latest blog post: Alice's Puzzle Page http://www.vroospeak.com
Learn how hackers think: http://j.mp/gruyere-security
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20131104/6903c914/attachment-0001.html>


More information about the Python-ideas mailing list