Title: Add a parameter to strip, lstrip, and rstrip that treats the first parameter as a full string
Type: enhancement Stage:
Components: Versions:
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: Chris Rogers, steven.daprano
Priority: normal Keywords:

Created on 2020-02-11 09:40 by Chris Rogers, last changed 2020-02-11 12:32 by steven.daprano.

Messages (2)
msg361791 - (view) Author: Chris Rogers (Chris Rogers) Date: 2020-02-11 09:40
Consider this string:


If you try to remove the mailtos with lstrip('mailto:'), you'll be left with this:


That's because the three strip functions look at each character separately rather than as a whole string.

Currently, as a workaround, you have to either use regex or a loop. This can take several lines of code.

It would be great if the strip functions had a second parameter that lets you keep the first parameter intact.

You could then use this code to get the desired result:

''.lstrip('mailto:', true)
msg361809 - (view) Author: Steven D'Aprano (steven.daprano) * (Python committer) Date: 2020-02-11 12:32
This has been discussed not long ago, it seems like it will need a PEP. See Brett's comment:

and various discussions:
Date User Action Args
2020-02-11 12:32:18steven.dapranosetnosy: + steven.daprano
messages: + msg361809
2020-02-11 09:40:20Chris Rogerscreate