[Tutor] url parsing

Emad Nawfal (عماد نوفل) emadnawfal at gmail.com
Sun Feb 15 13:37:50 CET 2009


On Sun, Feb 15, 2009 at 5:09 AM, Jay Jesus Amorin <jay.amorin at gmail.com>wrote:

> Hi,
>
> Can you please help my how to parse.
>
> url = http://this/is/my/url/to/parse
>
> how do i parse url to print "http://this/is/my/url/to"
>
> i want to remove the last part of my url with is "parse". I would like to
> remove the last string of my url.
>
> i have try split, but i think it wont work as i dont know how long my url
> would be in my real application.
>
> Thanks,
>
>
> Newbie,
>
> Jay
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>
> 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'
>>>




-- 
لا أعرف مظلوما تواطأ الناس علي هضمه ولا زهدوا في إنصافه كالحقيقة.....محمد
الغزالي
"No victim has ever been more repressed and alienated than the truth"

Emad Soliman Nawfal
Indiana University, Bloomington
http://emnawfal.googlepages.com
--------------------------------------------------------
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20090215/a812783e/attachment.htm>


More information about the Tutor mailing list