[Tutor] url parsing

Andre Engels andreengels at gmail.com
Sun Feb 15 14:22:09 CET 2009


On Sun, Feb 15, 2009 at 1:37 PM, Emad Nawfal (عماد نوفل)
<emadnawfal at gmail.com> wrote:

> I'm not sure this is the best strategy, but it seems to work:
>
>>>> url ="http://this/is/my/url/to/parse"
>>>> m = url.replace("//", '/').split("/")
>>>> n = m[0]+"//"+"/".join(new[1:])
>>>> n
> 'http://this/is/my/url/to'

What is 'new' in your solution? Apart from that, the following looks simpler:

>>> url = "http://this/is/my/url/to/parse"
>>> parts = url.split('/')
>>> sol = '/'.join(parts[:-1])
>>> sol
'http://this/is/my/url/to'




-- 
André Engels, andreengels at gmail.com


More information about the Tutor mailing list