Re: [Python-ideas] Complicate str methods

2018-02-03 Thread Franklin? Lee
On Sat, Feb 3, 2018 at 6:43 PM, Terry Reedy wrote: > On 2/3/2018 5:04 PM, Franklin? Lee wrote: >> >> Let s be a str. I propose to allow these existing str methods to take >> params in new forms. > > > Thanks for the honest title. As you sort of indicate, these can all be done >

Re: [Python-ideas] Complicate str methods

2018-02-03 Thread Steven D'Aprano
On Sun, Feb 04, 2018 at 10:54:53AM +1100, Chris Angelico wrote: > Picking up this one as an example, but this applies to all of them: > the transformation you're giving here is dangerously flawed. If there > are any regex special characters in the strings, this will either bomb > with an

Re: [Python-ideas] Complicate str methods

2018-02-03 Thread Chris Angelico
On Sun, Feb 4, 2018 at 10:43 AM, Terry Reedy wrote: > On 2/3/2018 5:04 PM, Franklin? Lee wrote: >> s.startswith, s.endswith: >> Allow argument to be a collection of strings. > > > bool(re.match('|'.join(strings)) does exactly the proposed s.startswith, > with the advantage

Re: [Python-ideas] Complicate str methods

2018-02-03 Thread Terry Reedy
On 2/3/2018 5:04 PM, Franklin? Lee wrote: Let s be a str. I propose to allow these existing str methods to take params in new forms. Thanks for the honest title. As you sort of indicate, these can all be done with re module. However, you imply loops are needed besides, which is mostly not

[Python-ideas] Complicate str methods

2018-02-03 Thread Franklin? Lee
Let s be a str. I propose to allow these existing str methods to take params in new forms. s.replace(old, new): Allow passing in a collection of olds. Allow passing in a single argument, a mapping of olds to news. Allow the olds in the mapping to be tuples of strings. s.split(sep),