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

2019-04-03 Thread Barry Scott
Use "without" as the action picking up on "with" as in startswith, endswith: new_string = a_string.withoutprefix( prefix ) new_string = a_sring.withoutsuffix( suffix ) And since we have "replace" "remove" would also seem obvious. new_string = a_string.removeprefix( prefix

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

2019-04-03 Thread MRAB
On 2019-04-03 03:06, Stephan Hoyer wrote: On Tue, Apr 2, 2019 at 5:43 PM Eric V. Smith > wrote: PS: I really tried to find a way to use := in this example so I could put the assignment inside the 'if' statement, but as I think Tim Peters pointed out, withou

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

2019-04-03 Thread MRAB
On 2019-04-03 09:38, Stephen J. Turnbull wrote: > MRAB writes: >  > On 2019-04-02 19:10, Stephen J. Turnbull wrote: > >  > >  word[len(prefix) if word.startswith(prefix) else 0:] > >  > It could be 'improved' more to: >  > >  >  word[word.startswith(prefix) and len(prefix) : ] > > Except t

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

2019-04-03 Thread Stephen J. Turnbull
MRAB writes: > On 2019-04-02 19:10, Stephen J. Turnbull wrote: > > word[len(prefix) if word.startswith(prefix) else 0:] > It could be 'improved' more to: > > word[word.startswith(prefix) and len(prefix) : ] Except that it would be asymmetric with suffix. That probably doesn't ma

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

2019-04-03 Thread Paul Moore
On Tue, 2 Apr 2019 at 23:58, Cameron Simpson wrote: > I think I find "might find it useful" more compelling than many do. Let > me explain. > > I think a _well_ _defined_ battery is worth including in the kit (str > methods) because: > > - the operation is simple and well defined: people won't be