strip() using strings instead of chars

Marc 'BlackJack' Rintsch bj_666 at gmx.net
Fri Jul 11 11:07:59 EDT 2008


On Fri, 11 Jul 2008 16:45:20 +0200, Christoph Zwerschke wrote:

> Bruno Desthuilliers schrieb:
>> DRY/SPOT violation. Should be written as :
>> 
>>  prefix = 'http://'
>>  if url.startswith(prefix):
>>      url = url[len(prefix):]
> 
> That was exactly my point. This formulation is a bit better, but it 
> still violates DRY, because you need to type "prefix" two times. It is 
> exactly this idiom that I see so often and that I wanted to simplify. 
> Your suggestions work, but I somehow feel such a simple task should have 
> a simpler formulation in Python, i.e. something like
> 
> url = url.lstripstr(('http://', 'https://'))

I would prefer a name like `remove_prefix()` instead of a variant with
`strip` and abbreviations in it.

Ciao,
	Marc 'BlackJack' Rintsch



More information about the Python-list mailing list