[ python-Bugs-940316 ] string.lstrip problem with '_' string
SourceForge.net
noreply at sourceforge.net
Thu Apr 22 16:48:09 EDT 2004
Bugs item #940316, was opened at 2004-04-22 15:36
Message generated for change (Settings changed) made by rhettinger
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=940316&group_id=5470
Category: Python Library
Group: Python 2.3
>Status: Closed
>Resolution: Invalid
Priority: 5
Submitted By: Arnold (arnaudf)
Assigned to: Nobody/Anonymous (nobody)
Summary: string.lstrip problem with '_' string
Initial Comment:
On Python 2.3.3, Windows 2000, standard installation
(just after running the msi installer)
Try this:
import string
string.lstrip('ORG_RESEAU','ORG_')
result is 'ESEAU' (problem)
Try this
string.lstrip('ORG_RESEAU','ORG_R')
result is 'ESEAU' (correct)
Try this
string.lstrip('ORG_RESEAU','ORG_RE')
result is 'SEAU' (correct)
It seems that cutting just after _ cuts also the next
character, specially if the next is R ? I have not tested
on Unix to see if its similar, but the behaviour of this
function is rather strange.
Any clue, did I miss something ?
Thanks anyway to the great Python project !
Arnold
----------------------------------------------------------------------
>Comment By: Raymond Hettinger (rhettinger)
Date: 2004-04-22 15:48
Message:
Logged In: YES
user_id=80475
The second argument is a character set not a prefix. So,
characters are stripped from the first argument until on is
found that is not in the second argument. This is useful
because it allows you strip any combination of leading
garbare characters:
>>> string.lstrip(' ** now here this',' *')
'now here this'
To strip a prefix, try something like this:
>>> s = 'ORG_RESEAU'
>>> prefix = 'ORG_'
>>> if s.startswith(prefix):
s = s[len(prefix):]
>>> s
'RESEAU'
----------------------------------------------------------------------
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=940316&group_id=5470
More information about the Python-bugs-list
mailing list