This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Python string.lstrip bug?
Type: behavior Stage:
Components: Build Versions: Python 2.6
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: mark.dickinson, mushywushy
Priority: normal Keywords:

Created on 2009-08-31 06:38 by mushywushy, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (2)
msg92102 - (view) Author: Andrew Liu (mushywushy) Date: 2009-08-31 06:38
A simple lstrip on the following causes an extra character to be
stripped, as per the below. Tried on 2.6.1 and on 2.4.3, as below.

Python 2.6.1 (r261:67515, Feb 27 2009, 02:54:13)
[GCC 4.3.2 20081105 (Red Hat 4.3.2-7)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> a = "contact_work_phone_no"
>>> a.lstrip("contact")
'_work_phone_no'
>>> a.lstrip("contact_")
'work_phone_no'
>>> a = "contact_city"
>>> a.lstrip("contact_")
'ity'
>>> a.lstrip("con")
'tact_city'
>>> a.lstrip("contact")
'_city'
>>> a.lstrip("contact_")
'ity'
>>>


Python 2.4.3 (#1, Mar 14 2007, 19:01:42)
[GCC 4.1.1 20070105 (Red Hat 4.1.1-52)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> a = "contact_city"
>>> a.lstrip("contact_")
'ity'
>>>
msg92104 - (view) Author: Mark Dickinson (mark.dickinson) * (Python committer) Date: 2009-08-31 06:58
This is not a bug:  the argument to lstrip effectively specifies a set 
of characters to be removed;  in your example, 'c' is in that set, so 
the 'c' at the beginning of city gets removed.  'i' is not in that set, 
so it stays. 

lstrip(...)
    S.lstrip([chars]) -> string or unicode
    
    Return a copy of the string S with leading whitespace removed.
    If chars is given and not None, remove characters in chars instead.
History
Date User Action Args
2022-04-11 14:56:52adminsetgithub: 51058
2009-08-31 06:58:19mark.dickinsonsetstatus: open -> closed

nosy: + mark.dickinson
messages: + msg92104

resolution: not a bug
2009-08-31 06:38:46mushywushycreate