Make a relative url path from an absolute path to another one

Andrei project5 at redrival.net
Mon Oct 27 11:41:40 EST 2003


Gilles Lenfant wrote on Mon, 27 Oct 2003 15:18:38 +0100:

> I'm sometimes brain dead for a simple problem like this one :
> 
> Given an origin absolute URL and a destination absolute URL, I want to make
> a relative path from the origin to the destination.
> 
> e.g
> 
> origin = http://www.stuff.com/x/y/foo.html
> destination = http://www.stuff.com/x/bar.html

You could split the strings at every "/" and compare the items of the two
resulting lists until two unidentical items are found. Then you've found
the common bit and the different bit and it's not that hard to make a
relative link for that.

-- 
Yours,

Andrei

=====
Mail address in header catches spam. Real contact info (decode with rot13):
cebwrpg5 at bcrenznvy.pbz. Fcnz-serr! Cyrnfr qb abg hfr va choyvp cbfgf. V
ernq gur yvfg, fb gurer'f ab arrq gb PP.






More information about the Python-list mailing list