On Tue, Jul 2, 2019 at 2:28 PM Glenn Linderman <v+python@g.nevcal.com> wrote:
A method could raise instead of returning the string as-is if the prefix is not really a prefix. How often is this needed? The most common end deletions are whitespace, which the current .strip handles correctly.
raising wouldn't be helpful in most of the situations where I use this logic... it would require a more complex flow control than the if startswith path in the current situation.
Yes, I use strip more frequently, but if startswith: chop_prefix operation (and the other end too) happens an awful lot.
If the method accepts a tuple of prefixes and will remove the first one found (or the longest, or whatever) and raises if none found, you could get the "chop only if present" behaviour by including an empty string as one of the possible prefixes. ChrisA