Re: strip() using strings instead of chars

2008-07-12 Thread Christoph Zwerschke
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

Re: strip() using strings instead of chars

2008-07-12 Thread Duncan Booth
Christoph Zwerschke [EMAIL PROTECTED] 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,

strip() using strings instead of chars

2008-07-11 Thread Christoph Zwerschke
In Python programs, you will quite frequently find code like the following for removing a certain prefix from a string: if url.startswith('http://'): url = url[7:] Similarly for stripping suffixes: if filename.endswith('.html'): filename = filename[:-5] My problem with this is that

Re: strip() using strings instead of chars

2008-07-11 Thread Bruno Desthuilliers
Christoph Zwerschke a écrit : In Python programs, you will quite frequently find code like the following for removing a certain prefix from a string: if url.startswith('http://'): url = url[7:] DRY/SPOT violation. Should be written as : prefix = 'http://' if url.startswith(prefix):

Re: strip() using strings instead of chars

2008-07-11 Thread Christoph Zwerschke
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

Re: strip() using strings instead of chars

2008-07-11 Thread Marc 'BlackJack' Rintsch
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

Re: strip() using strings instead of chars

2008-07-11 Thread Duncan Booth
Christoph Zwerschke [EMAIL PROTECTED] wrote: In Python programs, you will quite frequently find code like the following for removing a certain prefix from a string: if url.startswith('http://'): url = url[7:] If I came across this code I'd want to know why they weren't using