[Tutor] lstrip removes '/' unexpectedly
Tiger12506
keridee at jayco.net
Tue Dec 4 01:25:49 CET 2007
>> ##########################
>>>>> s = '/home/test/'
>>>>> s1 = s.lstrip('/ehmo')
>>>>> s1
>> 'test/'
>> ##########################
>>
>> Take a closer look at the documentation of lstrip, and you should see
>> that
>> what it takes in isn't treated as a prefix: rather, it'll be treated as a
>> set of characters.
>>
>
> But then the real bug is why does it not strip the trailing '/' in
> 'test/' or the 'e' that is in your set?
Because lstrip strips the characters within that set, starting from the
left,
until it encounters a character not in that set. Then it stops. This code
produces the same results, though surely more slowly.
def lstrip(s, set):
for x in s:
if x in set:
return lstrip(s[1:],set)
return s
JS
More information about the Tutor
mailing list