[Python-ideas] Re: Multiple arguments to str.partition and bytes.partition

2023-01-10 Thread Stephen J. Turnbull
James Addison via Python-ideas writes: > On Sun, 8 Jan 2023 at 08:32, Stephen J. Turnbull > wrote: > Trying to avoid the usual discussions about permissive parsing / > supporting various implementations in-the-wild: long-term, the least > ambiguous and most computationally-efficient environm

[Python-ideas] Re: Multiple arguments to str.partition and bytes.partition

2023-01-10 Thread Stephen J. Turnbull
Steven D'Aprano writes: > I mean, if all you are doing is splitting the source by some separators > regardless of order, surely this does the same job and is *vastly* more > obvious? > > >>> re.split(r'[:;]', 'foo:bar;baz') > ['foo', 'bar', 'baz'] "Obvious" yes, but it's also easy to inv

[Python-ideas] Re: Multiple arguments to str.partition and bytes.partition

2023-01-09 Thread dn
On 10/01/2023 01.19, James Addison wrote: On Sun, 8 Jan 2023 at 20:20, dn wrote: Herewith a repetition of an earlier repetition of a call for Python examples and use-cases. (to better justify the base-idea, which I support) (and hence earlier illustration/question: does the sep belong wit

[Python-ideas] Re: Multiple arguments to str.partition and bytes.partition

2023-01-09 Thread James Addison via Python-ideas
On Sun, 8 Jan 2023 at 20:20, dn wrote: > > (and hence earlier illustration/question: does the sep belong with the > string forming the left-side of that partition, or the 'right'?) There's no connection implied between each separator and the partitions that surround it in the results. In the use

[Python-ideas] Re: Multiple arguments to str.partition and bytes.partition

2023-01-08 Thread dn
On 08/01/2023 23.10, James Addison via Python-ideas wrote: On Sun, 8 Jan 2023 at 03:44, Steven D'Aprano wrote: Keep it nice and simple: provided with multiple separators, `partition` will split the string on the first separator found in the source string. In other words, `source.partition(a,

[Python-ideas] Re: Multiple arguments to str.partition and bytes.partition

2023-01-08 Thread Barry Scott
On 08/01/2023 17:06, James Addison wrote: On Sun, 8 Jan 2023 at 13:20, Barry Scott wrote: Maybe combine the ideas by allowing a tuple where a string is used. 'a=b;c'.partition('=', (':',';')) => ('a', '=', b, ';', 'c') I like that idea - and it seems to fit neatly with the existing partition

[Python-ideas] Re: Multiple arguments to str.partition and bytes.partition

2023-01-08 Thread James Addison via Python-ideas
On Sun, 8 Jan 2023 at 08:32, Stephen J. Turnbull wrote: > > Steven D'Aprano writes: > > > On Sat, Jan 07, 2023 at 10:48:48AM -0800, Peter Ludemann wrote: > > > You can get almost the same result using pattern matching. For example, > your > > > "foo:bar;baz".partition(":", ";") > > > can be d

[Python-ideas] Re: Multiple arguments to str.partition and bytes.partition

2023-01-08 Thread Steven D'Aprano
On Sun, Jan 08, 2023 at 05:30:30PM +0900, Stephen J. Turnbull wrote: > Steven D'Aprano writes: > > > On Sat, Jan 07, 2023 at 10:48:48AM -0800, Peter Ludemann wrote: > > > You can get almost the same result using pattern matching. For example, > your > > > "foo:bar;baz".partition(":", ";") > >

[Python-ideas] Re: Multiple arguments to str.partition and bytes.partition

2023-01-08 Thread James Addison via Python-ideas
On Sun, 8 Jan 2023 at 13:20, Barry Scott wrote: > Maybe combine the ideas by allowing a tuple where a string is used. > 'a=b;c'.partition('=', (':',';')) => ('a', '=', b, ';', 'c') I like that idea - and it seems to fit neatly with the existing partition contract: the inclusion of the matched-de

[Python-ideas] Re: Multiple arguments to str.partition and bytes.partition

2023-01-08 Thread Barry Scott
> On 8 Jan 2023, at 10:10, James Addison via Python-ideas > wrote: > > On Sun, 8 Jan 2023 at 03:44, Steven D'Aprano wrote: >> >> Keep it nice and simple: provided with multiple separators, `partition` >> will split the string on the first separator found in the source string. >> >> In othe

[Python-ideas] Re: Multiple arguments to str.partition and bytes.partition

2023-01-08 Thread James Addison via Python-ideas
On Sun, 8 Jan 2023 at 03:44, Steven D'Aprano wrote: > > Keep it nice and simple: provided with multiple separators, `partition` > will split the string on the first separator found in the source string. > > In other words, `source.partition(a, b, c, d)` will split on a /or/ b > /or/ c /or/ d, whic

[Python-ideas] Re: Multiple arguments to str.partition and bytes.partition

2023-01-08 Thread Stephen J. Turnbull
Steven D'Aprano writes: > On Sat, Jan 07, 2023 at 10:48:48AM -0800, Peter Ludemann wrote: > > You can get almost the same result using pattern matching. For example, > > your > > "foo:bar;baz".partition(":", ";") > > can be done by a well-known matching idiom: > > re.match(r'([^:]*):([^;]*)

[Python-ideas] Re: Multiple arguments to str.partition and bytes.partition

2023-01-07 Thread Steven D'Aprano
On Sat, Jan 07, 2023 at 10:48:48AM -0800, Peter Ludemann wrote: > You can get almost the same result using pattern matching. For example, your > "foo:bar;baz".partition(":", ";") > can be done by a well-known matching idiom: > re.match(r'([^:]*):([^;]*);(.*)', 'foo:bar;baz').groups() "Well-known"

[Python-ideas] Re: Multiple arguments to str.partition and bytes.partition

2023-01-07 Thread Steven D'Aprano
+1 on the idea of having `partition` and `rpartition` take multiple separators. Keep it nice and simple: provided with multiple separators, `partition` will split the string on the first separator found in the source string. In other words, `source.partition(a, b, c, d)` will split on a /or/ b

[Python-ideas] Re: Multiple arguments to str.partition and bytes.partition

2023-01-07 Thread dn
On 08/01/2023 00.56, James Addison via Python-ideas wrote: # Feature or enhancement The str.partition[1] method -- and similarly the bytes.partition[2] method -- is useful when dividing an input into subcomponents while returning a tuple of deterministic length (currently 3) and potentially retai

[Python-ideas] Re: Multiple arguments to str.partition and bytes.partition

2023-01-07 Thread Peter Ludemann
You can get almost the same result using pattern matching. For example, your "foo:bar;baz".partition(":", ";") can be done by a well-known matching idiom: re.match(r'([^:]*):([^;]*);(.*)', 'foo:bar;baz').groups() ___ Python-ideas mailing list -- python-id