Issue 940316: string.lstrip problem with '_' string (original) (raw)
Issue940316
Created on 2004-04-22 20:36 by arnaudf, last changed 2022-04-11 14:56 by admin. This issue is now closed.
Messages (3) | ||
---|---|---|
msg20564 - (view) | Author: Arnold (arnaudf) | Date: 2004-04-22 20:36 |
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 | ||
msg20565 - (view) | Author: Raymond Hettinger (rhettinger) * ![]() |
Date: 2004-04-22 20:48 |
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' | ||
msg20566 - (view) | Author: Uwe Hoffmann (qual) | Date: 2004-04-22 20:49 |
Logged In: YES user_id=337146 the second parameter has another meaning: lstrip removes all characters on the left from the first parameter contained in the second parameter ( the second parameter is treated as a list of characters, not as a string) string.lstrip('ORG_RESEAU','ORG_') result is 'ESEAU' ( *no* problem) because R is contained in "ORG_" |
History | |||
---|---|---|---|
Date | User | Action | Args |
2022-04-11 14:56:03 | admin | set | github: 40178 |
2004-04-22 20:36:09 | arnaudf | create |