classification
Title: lstrip 处理出现bug
Type: behavior Stage: resolved
Components: Extension Modules Versions: Python 3.7
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: christian.heimes, eryksun, wsqat
Priority: normal Keywords:

Created on 2020-11-18 10:13 by wsqat, last changed 2020-11-18 14:23 by eryksun. This issue is now closed.

Messages (3)
msg381323 - (view) Author: sagewang (wsqat) Date: 2020-11-18 10:13
>>> "prefix_prj_t_suffix".strip().lstrip('prefix_prj_').rstrip('_suffix')
't'
>>> "data_prj_t_suffix".strip().lstrip('data_prj_').rstrip('_suffix')
''
msg381324 - (view) Author: Christian Heimes (christian.heimes) * (Python committer) Date: 2020-11-18 10:17
The methods works as designed and documented. The arguments to str.strip, lstrip, and rstrip methods are not prefixes / suffixes. They are sets of characters.

>>> "bad".lstrip("ab")
'd'

https://docs.python.org/3/library/stdtypes.html?highlight=lstrip#str.lstrip
msg381344 - (view) Author: Eryk Sun (eryksun) * (Python triager) Date: 2020-11-18 14:23
Python 3.9 added str.removeprefix() and str.removesuffix() [1]:

    >>> "data_prj_t_suffix".removeprefix('data_prj_').removesuffix('_suffix')
    't'

[1] https://docs.python.org/3/library/stdtypes.html#str.removeprefix
History
Date User Action Args
2020-11-18 14:23:15eryksunsetnosy: + eryksun
messages: + msg381344
2020-11-18 10:17:12christian.heimessetstatus: open -> closed

nosy: + christian.heimes
messages: + msg381324

resolution: not a bug
stage: resolved
2020-11-18 10:13:31wsqatcreate