Re: [Tutor] Replacing part of a URL

2010-02-20 Thread spir
On Sun, 21 Feb 2010 11:25:31 +1100 Steven D'Aprano wrote: > "Some people, when confronted with a problem, think 'I know, I'll use > regular expressions.' Now they have two problems." -- Jamie Zawinski ;-) la vita e estrany http://spir.wikidot.com/ ___

Re: [Tutor] Replacing part of a URL

2010-02-20 Thread Steven D'Aprano
On Sun, 21 Feb 2010 09:34:34 am Lao Mao wrote: > Hello, > > I need to be able to replace the last bit of a bunch of URLs. > > The urls look like this: > > www.somesite.com/some/path/to/something.html > > They may be of varying lengths, but they'll always end with > .something_or_other.html > > I wa

Re: [Tutor] Replacing part of a URL

2010-02-20 Thread Kent Johnson
On Sat, Feb 20, 2010 at 5:34 PM, Lao Mao wrote: > Hello, > I need to be able to replace the last bit of a bunch of URLs. > The urls look like this: > www.somesite.com/some/path/to/something.html > They may be of varying lengths, but they'll always end with > .something_or_other.html > I want to ta

Re: [Tutor] Replacing part of a URL

2010-02-20 Thread Shashwat Anand
> > They may be of varying lengths, but they'll always end with > .something_or_other.html > Missed this point. You can use posixpath module too as an option. >>> url = 'http://www.somesite.com/some/path/to/something.html >>> var = 'anotherthing' >>> posixpath.dirname(url) 'http://www.somesite.com

Re: [Tutor] Replacing part of a URL

2010-02-20 Thread Shashwat Anand
>>> url = 'http://www.somesite.com/some/path/to/something.html' >>> var = 'anotherthing' >>> i = url.rfind('/') + 1 >>> j = url.rfind('.') >>> if i < j: ... newurl = url[:i] + var + url[j:] ... else: ... newurl = url[:i] + var >>> newurl 'http://www.somesite.com/some/path/to/anotherthing.ht

[Tutor] Replacing part of a URL

2010-02-20 Thread Lao Mao
Hello, I need to be able to replace the last bit of a bunch of URLs. The urls look like this: www.somesite.com/some/path/to/something.html They may be of varying lengths, but they'll always end with .something_or_other.html I want to take the "something" and replace it with something else. My