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

2023-01-07 Thread James Addison via Python-ideas
Hi folks, I'd like to gather some feedback on a feature suggestion to extend str.partition and bytes.partition to support multiple arguments. Please find the feature described below. # Feature or enhancement The str.partition[1] method -- and similarly the bytes.partition[2] method -- is useful w

[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

[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 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 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"