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
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,
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
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):
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
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
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