strip() using strings instead of chars

Duncan Booth duncan.booth at invalid.invalid
Sat Jul 12 19:36:01 CEST 2008


Christoph Zwerschke <cito at online.de> wrote:

> Duncan Booth schrieb:
>>> if url.startswith('http://'):
>>>      url = url[7:]
>> 
>> If I came across this code I'd want to know why they weren't using 
>> urlparse.urlsplit()...
> 
> Right, such code can have a smell since in the case of urls, file names, 
> config options etc. there are specialized functions available. But I'm 
> not sure whether the need for removing string prefix/suffixes in general 
> is really so rare that we shouldn't worry to offer a simpler solution.
> 

One of the great things about Python is that it resists bloating the 
builtin classes with lots of methods that just seem like a good idea at the 
time. If a lot of people make a case for this function then it might get 
added, but I think it is unlikely given how simple it is to write a 
function to do this for yourself.



More information about the Python-list mailing list