<div dir="ltr"><div dir="ltr">On Sun, Mar 31, 2019 at 12:09 PM MRAB <<a href="mailto:python@mrabarnett.plus.com">python@mrabarnett.plus.com</a>> wrote:<br></div><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">> That said, I really like Brandt's ideas of expanding the signature of <br>
> .lstrip/.rstrip instead.<br>
> <br>
> mystring.rstrip("abcd") # remove any of these single character suffixes<br><br>
It removes _all_ of the single character suffixes.<br>
<br>
> mystring.rstrip(('foo', 'bar', 'baz')) # remove any of these suffixes<br><br>
In keeping with the current behaviour, it would strip _all_ of these <br>
suffixes.<br></blockquote><div><br></div><div>Yes, the exact behavior would need to be documented.  The existing case indeed removes *ALL* of the single letter suffixes.  Clearly that behavior cannot be changed (nor would I want to, that behavior is useful).</div><div><br></div><div>It's a decision about whether passing a tuple of substrings would remove all of them (perhaps repeatedly) or only one of them.  And if only one, is it "longest wins" or "first wins."  As I say, any choice of the semantics would be fine with me if it were documented... since this edge case will be uncommon in most uses (certainly in almost all of my uses).</div><div><br></div><div>E.g.</div><div><br></div><div>    basename = fname.rstrip(('.jpg', '.png', 'gif')) </div></div><div><br></div><div>This is rarely ambiguous, and does something concretely useful that I've coded many times.  But what if:</div><div><br></div><div>    fname = 'silly.jpg.png.gif.png.jpg.gif.jpg'</div><div><br></div><div>I'm honestly not sure what behavior would be useful most often for this oddball case.  For the suffixes, I think "remove them all" is probably the best; that is consistent with thinking of the string passed in the existing signature of .rstrip() as an iterable of characters.</div><div><br></div><div>But even if the decision was made to "only remove the single thing at end", I'd still find the enhancement useful.  Sure, once in a while someone might trip over the choice of semantics in this edge case, but if it were documented, no big deal.</div><div><br></div>-- <br><div dir="ltr" class="gmail_signature">Keeping medicines from the bloodstreams of the sick; food <br>from the bellies of the hungry; books from the hands of the <br>uneducated; technology from the underdeveloped; and putting <br>advocates of freedom in prisons.  Intellectual property is<br>to the 21st century what the slave trade was to the 16th.<br></div></div>