[Python-ideas] Re: str.strip: argument maxstrip

2020-05-20 Thread Alex Hall
On Wed, May 20, 2020 at 12:44 PM Henk-Jaap Wagenaar < wagenaarhenkj...@gmail.com> wrote: > foobar.removesuffix('=').removesuffix('=') > > would work right now in 3.9 (I think). > > Can confirm: ``` >>> 'abc==='.removesuffix('=').removesuffix('=') 'abc='

[Python-ideas] Re: str.strip: argument maxstrip

2020-05-20 Thread Henk-Jaap Wagenaar
On Wed, 20 May 2020 at 11:34, Alex Hall wrote: > On Wed, May 20, 2020 at 2:46 AM Cameron Simpson wrote: > >> On 19May2020 15:43, David Mertz wrote: >> Reiterating the Python 3.9 suggestion, what about: >> >> salt2 = salt.cutsuffix(('==', '=')) >> > > But if the API was there, I agree this

[Python-ideas] Re: str.strip: argument maxstrip

2020-05-20 Thread Alex Hall
On Wed, May 20, 2020 at 2:46 AM Cameron Simpson wrote: > On 19May2020 15:43, David Mertz wrote: > Reiterating the Python 3.9 suggestion, what about: > > salt2 = salt.cutsuffix(('==', '=')) > Tuple arguments were rejected in the PEP. ``` Python 3.10.0a0 (heads/master:bac170cd93, May 20 2020,

[Python-ideas] Re: str.strip: argument maxstrip

2020-05-19 Thread David Mertz
On Tue, May 19, 2020 at 8:43 PM Cameron Simpson wrote: > >salt = salt.rstrip("=", maxstrip=2) > >assert not salt.endswith("=") > > Reiterating the Python 3.9 suggestion, what about: > > salt2 = salt.cutsuffix(('==', '=')) > You'd have to call cutsuffix twice. Valid base64 might end in one,

[Python-ideas] Re: str.strip: argument maxstrip

2020-05-19 Thread Cameron Simpson
On 19May2020 15:43, David Mertz wrote: I may be misunderstanding, but it sounds like = is not acceptable in the final result, so it's not enough to remove only 2 of 4 ='s. You want to make sure nothing messed up your string. So if the code existed, what you'd want is: ``` assert

[Python-ideas] Re: str.strip: argument maxstrip

2020-05-19 Thread David Mertz
On Tue, May 19, 2020 at 3:50 PM Alex Hall wrote: > Anyway, you could write: > assert not salt.endswith("=" * 3) # at most 2 ='s allowed > salt = salt.rstrip("=") > Yes, I *could* write that. It feels a bit more cryptic than the version I mentioned. But it's fine. -- The dead increasingly

[Python-ideas] Re: str.strip: argument maxstrip

2020-05-19 Thread Alex Hall
On Tue, May 19, 2020 at 9:43 PM David Mertz wrote: > Currently, I'd probably program my intention like this. Let's assume this > is something where the '=' is allowed in the middle. > Getting increasingly hypothetical... Anyway, you could write: ``` assert not salt.endswith("=" * 3) # at

[Python-ideas] Re: str.strip: argument maxstrip

2020-05-19 Thread David Mertz
> > I may be misunderstanding, but it sounds like = is not acceptable in the > final result, so it's not enough to remove only 2 of 4 ='s. You want to > make sure nothing messed up your string. So if the code existed, what you'd > want is: > ``` > assert salt.count("=") <= 2 > salt =

[Python-ideas] Re: str.strip: argument maxstrip

2020-05-19 Thread Alex Hall
On Tue, May 19, 2020 at 2:58 PM computermaster360 . < computermaster...@gmail.com> wrote: > I often find myself in a need of stripping only a specified amount of > characters from a string (most commonly a single character). I have been > implementing this in an ad-hoc manner, which is quite

[Python-ideas] Re: str.strip: argument maxstrip

2020-05-19 Thread Alex Hall
On Tue, May 19, 2020 at 8:49 PM David Mertz wrote: > elif fmt == "PBKDF2_SHA256": > h = base64.b64encode(base64.b64decode(text)[:32]) > # a terrible hack follows, use "adapted base64" alphabet > (using . instead of + and with no padding) > h =

[Python-ideas] Re: str.strip: argument maxstrip

2020-05-19 Thread David Mertz
I did a couple greps of my git/ directory to see if I found examples. Given that there are a couple ways one might achieve the effect now, I don't necessarily find everything. But here's something in software I did not write myself. This is from ./JohnTheRipper/run/sspr2john.py. I found another

[Python-ideas] Re: str.strip: argument maxstrip

2020-05-19 Thread Alex Hall
On Tue, May 19, 2020 at 8:10 PM Henk-Jaap Wagenaar < wagenaarhenkj...@gmail.com> wrote: > David (or somebody else) could you give us some, as real as possible, > examples? This will strengthen the case for it! > > I am confident they exist and are pretty plentiful but I myself am coming > up

[Python-ideas] Re: str.strip: argument maxstrip

2020-05-19 Thread Henk-Jaap Wagenaar
David (or somebody else) could you give us some, as real as possible, examples? This will strengthen the case for it! I am confident they exist and are pretty plentiful but I myself am coming up blank thinking about it for a few minutes and documenting them would be good for discussion. On Tue,

[Python-ideas] Re: str.strip: argument maxstrip

2020-05-19 Thread David Mertz
I think this would be useful, and doesn't break any backward compatibility. I would have use for it from time to time myself. On Tue, May 19, 2020 at 9:01 AM computermaster360 . < computermaster...@gmail.com> wrote: > I often find myself in a need of stripping only a specified amount of >

[Python-ideas] Re: str.strip: argument maxstrip

2020-05-19 Thread computermaster360 .
Jonathan Goble wrote: > > Do you mean "str.strip, str.lstrip, str.rstrip"? Yes, I meant that. ___ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org

[Python-ideas] Re: str.strip: argument maxstrip

2020-05-19 Thread Rob Cliffe via Python-ideas
To strip at most 1 character from the end:     txt[:-1] + txt[-1:].rstrip(chars) To strip at most N characters:     txt[:-N] + txt[-N:].rstrip(chars) Given that, I think yours is too much of a niche case to change anything in Python Rob Cliffe On 19/05/2020 12:44, computermaster360 . wrote: I

[Python-ideas] Re: str.strip: argument maxstrip

2020-05-19 Thread Jonathan Goble
On Tue, May 19, 2020 at 9:00 AM computermaster360 . < computermaster...@gmail.com> wrote: > I often find myself in a need of stripping only a specified amount of > characters from a string (most commonly a single character). I have been > implementing this in an ad-hoc manner, which is quite