[Python-ideas] oneof() and multi split and replace for stirngs

Calvin Spealman ironfroggy at gmail.com
Tue Jan 23 07:10:21 CET 2007

I don't know if this would make sense to try to push to 2.6 or 3.0. I
was talking with some people about how the ability to split or replace
on multiple substrings would be added to python, without adding new
methods or having ugly tuple passing requirents like s.split(('foo',
'bar'), 4). This idea came to mind, so I wanted to toss it out there
for scrutination. It would be a builtin, but can be implemented in
python like this, basically:

class oneof(list):
    def __init__(self, *args):
    def __eq__(self, o):
        return o in self

assert 'bar' == oneof('bar', 'baz')

In addition to the new type, .replace, .split, and other appropriate
functions would be updated to take this as the substring argument to
locate and would match any one of the substrings it contains. I've
asked a few people and gotten good responses on the general idea so
far, but what do you all think?

1) Would the multi-substring operations be welcomed?
2) Could this be a good way to add those to the API without breaking things?
3) What version would it target?
4) What all functions and methods should support this or generally
might gain value from some similar solution?

Read my blog! I depend on your acceptance of my opinion! I am interesting!

More information about the Python-ideas mailing list