[Python-Dev] partition() (was: Remove str.find in 3.0?)

Delaney, Timothy (Tim) tdelaney at avaya.com
Tue Aug 30 01:31:34 CEST 2005


Michael Chermside wrote:

> Raymond writes:
>> That suggests that we need a variant of split() that has been
>> customized for typical find/index use cases.  Perhaps introduce a
>> new pair of methods, partition() and rpartition()
> 
> +1
> 
> My only suggestion is that when you're about to make a truly
> inspired suggestion like this one, that you use a new subject
> header. It will make it easier for the Python-Dev summary
> authors and for the people who look back in 20 years to ask
> "That str.partition() function is really swiggy! It's everywhere
> now, but I wonder what language had it first and who came up with
> it?"

+1

This is very useful behaviour IMO.

Have the precise return values of partition() been defined?
Specifically, given:

    'a'.split('b')

we could get back:

    ('a', '', '')
    ('a', None, None)

Similarly:

    'ab'.split('b')

could be either:

    ('a', 'b', '')
    ('a', 'b', None)

IMO the most useful (and intuitive) behaviour is to return strings in
all cases.

My major issue is with the names - partition() doesn't sound right to
me. split() of course sounds best, but it has additional stuff we don't
necessarily want. However, I think we should aim to get the idea
accepted first, then work out the best name.

Tim Delaney


More information about the Python-Dev mailing list