On Mar 30, 2019, at 12:30, MRAB <python@mrabarnett.plus.com> wrote:
I'd much prefer .lcut/.rcut to .cut_prefix/.cut_suffix, to match .lstrip/.rstrip.
I agree that we should use either l/r or something to do with start/end. We already have two different ways to say left/start and right/end on the str methods; adding a third way to say left/start/prefix seems silly. But I don’t like cut. Or trim, or any of the other options. They’re all just synonyms for strip; there’s nothing about any of these synonyms that tells you, implies, or even helps you remember that strip takes an iterable of characters and cut takes a substring (or is that a substring or tuple of substrings?) instead of the other way around. A name like lstrip_string would solve that. But so would modifying lstrip to take keyword arguments: s.lstrip("abc") # same as today s.lstrip(chars="abc") # same as above s.lstrip(string="abc") # the new functionality: only strip the whole thing Also, this means that if we do want the substring-or-substrings thing, we don’t have to use the old tuple idiom; since it’s a keyword-only param, we could just as easily have a different keyword param that accepts any iterable of strings. So when you have a set of prefixes, you don’t have to call s.lcut(tuple(prefixes)), you just pass the set as-is to s.lstrip(strings=prefixes)).