[Python-ideas] Re: New explicit methods to trim strings

2020-03-07 Thread Alex Hall
I've defined functions like this in my own utility library and I use them all the time, so I think they're very useful and would like to seem them built in. But I have two functions for each end: def strip_optional_suffix(string, suffix): """ >>> strip_optional_suffix('abcdef', 'def')

[Python-ideas] Re: New explicit methods to trim strings

2020-03-07 Thread Ethan Furman
On 03/07/2020 05:31 AM, Alex Hall wrote: I've defined functions like this in my own utility library and I use them all the time, so I think they're very useful and would like to seem them built in. But I have two functions for each end: def strip_optional_suffix(string, suffix): ... def

[Python-ideas] Re: New explicit methods to trim strings

2020-03-07 Thread Guido van Rossum
On Sat, Mar 7, 2020 at 7:06 AM Ethan Furman wrote: > On 03/07/2020 05:31 AM, Alex Hall wrote: > > > I've defined functions like this in my own utility library and I use them > > all the time, so I think they're very useful and would like to seem them > > built in. But I have two functions for e

[Python-ideas] Re: New explicit methods to trim strings

2020-03-07 Thread Cameron Simpson
On 07Mar2020 15:31, Alex Hall wrote: I've defined functions like this in my own utility library and I use them all the time, so I think they're very useful and would like to seem them built in. But I have two functions for each end: def strip_optional_suffix(string, suffix): """ >>> strip

[Python-ideas] Re: New explicit methods to trim strings

2020-03-07 Thread Cameron Simpson
On 07Mar2020 08:26, Guido van Rossum wrote: Maybe. FWIW, I looked at what a few other languages offer, and found that in Go, they use Trim(s, chars) for our s.strip(chars), and they have separate TrimPrefix and TrimSuffix methods. That seems the best solution of the bunch, so I am now okay with

[Python-ideas] Re: New explicit methods to trim strings

2020-03-07 Thread Christopher Barker
On Fri, Mar 6, 2020 at 5:54 PM Guido van Rossum wrote: > > (Since bytes may be used for file names I think they should get this new > capability too.) > >> >> I don’t really care one way or another, but is it really still the case >> that bytes need to be used for filenames? For uses other than j

[Python-ideas] Re: New explicit methods to trim strings

2020-03-07 Thread Christopher Barker
On Sat, Mar 7, 2020 at 3:01 PM Cameron Simpson wrote: > Like yours, they return the original object if unchanged. that makes me uncomfortable, but I guess as srings are mutable (an may be interned, why not?) Do the other string methods return themselves if there is no change? As for the "requ

[Python-ideas] Re: New explicit methods to trim strings

2020-03-07 Thread Chris Angelico
On Sun, Mar 8, 2020 at 10:10 AM Christopher Barker wrote: > > On Sat, Mar 7, 2020 at 3:01 PM Cameron Simpson wrote: >> >> Like yours, they return the original object if unchanged. > > > that makes me uncomfortable, but I guess as srings are mutable (an may be > interned, why not?) > > Do the oth

[Python-ideas] Re: New explicit methods to trim strings

2020-03-07 Thread MRAB
On 2020-03-07 23:01, Cameron Simpson wrote: On 07Mar2020 08:26, Guido van Rossum wrote: Maybe. FWIW, I looked at what a few other languages offer, and found that in Go, they use Trim(s, chars) for our s.strip(chars), and they have separate TrimPrefix and TrimSuffix methods. That seems the best

[Python-ideas] prefix/suffix for bytes (was: New explicit methods to trim strings)

2020-03-07 Thread Cameron Simpson
On 07Mar2020 15:01, Christopher Barker wrote: On Fri, Mar 6, 2020 at 5:54 PM Guido van Rossum wrote: (Since bytes may be used for file names I think they should get this new capability too.) I don’t really care one way or another, but is it really still the case that bytes need to be used f

[Python-ideas] Re: New explicit methods to trim strings

2020-03-07 Thread Cameron Simpson
On 08Mar2020 00:17, MRAB wrote: On 2020-03-07 23:01, Cameron Simpson wrote: I'm somewhat against "strip" in the name, because Python's plain "strip" methods act like PHP and Go trim methods: they strip multiple characters, not fixed strings. My own preference (and personal library use) is cut

[Python-ideas] Re: New explicit methods to trim strings

2020-03-07 Thread Christopher Barker
On Sat, Mar 7, 2020 at 4:36 PM Cameron Simpson wrote: > >Go's Trim strips multiple characters, but, as far as I can tell from > >the docs, TrimPrefix and TrimSuffix strip a single prefix/suffix > >string. > > And right there is the confusion I'd rather avoid. I'd like the affix > stuff to have a

[Python-ideas] Re: New explicit methods to trim strings

2020-03-07 Thread MRAB
On 2020-03-08 01:51, Christopher Barker wrote: > On Sat, Mar 7, 2020 at 4:36 PM Cameron Simpson wrote: > >> Go's Trim strips multiple characters, but, as far as I can tell from >> the docs, TrimPrefix and TrimSuffix strip a single prefix/suffix >> string. > > And right there is the confusion I'd

[Python-ideas] Re: New explicit methods to trim strings

2020-03-07 Thread Cameron Simpson
On 07Mar2020 17:51, Christopher Barker wrote: On Sat, Mar 7, 2020 at 4:36 PM Cameron Simpson wrote: >Go's Trim strips multiple characters, but, as far as I can tell from >the docs, TrimPrefix and TrimSuffix strip a single prefix/suffix >string. And right there is the confusion I'd rather avoi