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 retaining the delimiters.
The feature described here adds support for multiple positional arguments to
those methods.
Like the idea of being able to supply a list of separators. In which
case, the return would need to indicate which separator was being
applied to which partitioning (see below).
The first positional argument would be applied to the input instance that the
method is called from -- no change from existing behaviour.
Subsequent positional arguments would be applied to the rightmost component of
the previous application of the partition algorithm.
This part seemed an unnecessary limitation - why imply an order?
Why isn't the definition of the first partition: that part of the string
up-to (but not including) the first of any of the provided
separator-strings?
For example:
login_string = 'username@hostname:2001'
username, _, hostname, _, port = login_string.partition('@', ':')
Would be better to provide an example which is not already performed by
two path libraries.
Also, would like to see how are thinking the resulting construct
would/could be processed, ie how to consume the resulting tuple.
Might it be better to produce a set of tuple-pairs?
result = ( ( 'foo', ':', ),
( 'bar', ';', ),
( 'baz', ),
)
or indeed:
result = ( ( 'foo', ),
( ':', 'bar', ),
( ';', 'baz', ),
)
NB partition() currently returns a tuple of strings, do you intend to
also propose output as a list?
--
--
Regards,
=dn
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at
https://mail.python.org/archives/list/python-ideas@python.org/message/IZALZ4SG7XGOPH4DDUULPVCM2IMFI5CE/
Code of Conduct: http://python.org/psf/codeofconduct/