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://'))
instead of
for prefix in ('http://', 'https://'):
if url.startswith(prefix):
url = url[len(prefix):]
break
-- Christoph
--
http://mail.python.org/mailman/listinfo/python-list